Created
October 30, 2021 09:58
-
-
Save naemazam/25a60f0e45bb6138b9017726d9248e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Create a one-dimensional all 0 ndarray object with length n, and then make | |
the m-th element equal to 1 | |
Enter n, m separated by spaces, and n > = m | |
[sample input] | |
10 5 | |
[sample output] | |
[[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]] | |
''' | |
import numpy as np | |
n, m = input().split() | |
n =int(n) | |
m = int(m) | |
new_list= [] | |
for i in range(n): | |
if i == m-1: | |
new_list.append(1) | |
else: | |
new_list.append(0) | |
x = np.array([new_list]) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do it by this way
import numpy as np
n,m=map(int,input("Enter n,m: ").split())
ans=np.zeros(n)
ans[m-1]=1
print(ans)