import numpy as np
n = 4
i = 3
e = 10
array_nums1 = np.zeros((n,n))
print("Original array:")
print(array_nums1)
np.put(array_nums1, np.random.choice(range(n*n), i, replace=False), e)
print("\nPlace a specified element in specified time randomly:")
print(array_nums1)
Sample Output:
Original array:
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
Place a specified element in specified time randomly:
[[10. 0. 0. 0.]
[10. 0. 0. 0.]
[ 0. 0. 0. 10.]
[ 0. 0. 0. 0.]]
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer