Hi everyone
I have a 3d numpy array called p as follows
[[0, 2, 1],
[3, 7, 5],
[9, 7, 6]],
What I want to achieve is to "gate" p with q. In other words for any position in axis 0 in p I want a comparison to be made with the corresponding position in 1. if the corresponding value in is greater than p, I want to replace the value in p with the number 130.
The correct answer should be a 3d numpy array as follows
array([[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]],
[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]],
[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]]])
So first the values at p[0][0][0] and p[1][0][0] and p[2][0][0] are all compared with the value at q[0][0]. If the value in p is less than the value in q the value in p is substituted with 130.
So first the values at p[0][1][2] and p[1][1][2] and p[1][1][2] are all compared with the value at q[1][2]. If the value in p is less than the value in q the value in p is substituted with 130.
I have tried to code this as follows
p
array([[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]],
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]],
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]]])
q
array [[0, 2, 1],
[3, 7, 5],
[9, 7, 6]],
j=np.where(q[:]>p[:],p,130]
SyntaxError: invalid syntax
How can I use np.where to substitute the value 130 along each axis 0 position in P with teh corresponding position in q?
Thanks Peter
I have a 3d numpy array called p as follows
array([[[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[0, 1, 2], [3, 4, 5], [6, 7, 8]], [[0, 1, 2], [3, 4, 5], [6, 7, 8]]])I also have a 2d numpy array called q as follows
[[0, 2, 1],
[3, 7, 5],
[9, 7, 6]],
What I want to achieve is to "gate" p with q. In other words for any position in axis 0 in p I want a comparison to be made with the corresponding position in 1. if the corresponding value in is greater than p, I want to replace the value in p with the number 130.
The correct answer should be a 3d numpy array as follows
array([[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]],
[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]],
[[0, 130, 2],
[3, 130, 5],
[130, 7, 8]]])
So first the values at p[0][0][0] and p[1][0][0] and p[2][0][0] are all compared with the value at q[0][0]. If the value in p is less than the value in q the value in p is substituted with 130.
So first the values at p[0][1][2] and p[1][1][2] and p[1][1][2] are all compared with the value at q[1][2]. If the value in p is less than the value in q the value in p is substituted with 130.
I have tried to code this as follows
p
array([[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]],
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]],
[[0, 1, 2],
[3, 4, 5],
[6, 7, 8]]])
q
array [[0, 2, 1],
[3, 7, 5],
[9, 7, 6]],
j=np.where(q[:]>p[:],p,130]
SyntaxError: invalid syntax
How can I use np.where to substitute the value 130 along each axis 0 position in P with teh corresponding position in q?
Thanks Peter