array statement in python -
i have matrix
1 2 3 4 5 6 7 8 9
i want combine first element other element of same matrix , create new matrix.
x , y ndarray want code in python
for i=0 3 j=0 3 if x[0][0]<x[i][j] t[i][j]=1 else t[i][j]=0
in python:
x=np.array([[1,2,3], [4,5,6], [7,8,9]]) y=[] in range(0, 3): j in range(0, 3): if x[0][0]< x[i][j]: y.append(1) else: y.append(0)
out put:
>>> t [0, 1, 1, 1, 1, 1, 1, 1, 1]
is statement correct ?
first, when run code stated, value y, not value pasted:
[0, 1, 1, 1, 1, 1, 1, 1, 1]
i suspect you're trying not have written here, assuming is, here's easier way achieve same result:
>>> np.where(x > x[0,0], 1, 0).flatten() array([0, 1, 1, 1, 1, 1, 1, 1, 1])
Comments
Post a Comment