I am doing this as shown below. Initially I have a 2D array A = [(1,2,3) , (4,5,6)]. Now through a function func , I want to replace all the elements in both the two rows of array A by random numbers. I am trying but I am getting every element as 0 after execution of the function. Can somebody help. Remember I have to do this problem by using this function func and doing these slicing operations.
import numpy as np
import random
A=np.array([(1,2,3),(4,5,6)])
def func(B):
B[0:3]= np.random.random((1,3))
return(B)
for ic in range(0,2):
A[ic,:]= func(A[ic,:])
print(A)
Output
Everytime I am getting zeros. There should be random numbers in both the rows of array A . I think the random number generator is generating zeros every time. Can somebody help ??
[[0 0 0]
[0 0 0]]