I have the following numpy array:
x = [[1,2],[3,4],[10,1]]
y = [[5,6],[1,8],[7,8]]
z = [[10,2],[9,10],[11,12]]
xyz = np.array([x,y,z])
I want to remove rows with value 10 in the first column of each of x
, y
, z
within xyz
. So my desired output:
array([[[ 1, 2],
[ 3, 4]],
[[ 5, 6],
[ 1, 8],
[ 7, 8]],
[[ 9, 10],
[11, 12]]], dtype=object)
I tried xyz[xyz[:,:,0]!=10]
but this doesn't preserve the 3-dimensional nature of xyz
. I guess I can iterate over the first dimension, slice and append to a new array but I'm looking for a simpler (possibly a one-liner) solution.
question from:
https://stackoverflow.com/questions/65889016/removing-rows-from-subarrays-of-a-numpy-array-based-on-a-condition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…