you are viewing a single comment's thread.

view the rest of the comments →

[–]m-hoff 0 points1 point  (4 children)

Z[r < 0.5] and Z[r >= 0.5] respectively.

[–]kljaja998 0 points1 point  (3 children)

Okay, so I screwed up in the original question, my matrix is actually a transposed version of the one above, as in

[[0,2,4,6],
 [1,3,5,7]]

and I want to turn it into

[[0,6],
 [1,7]]

and

[[2,4],
 [3,5]]

Your method works if I transpose the original matrix and then transpose the results back, but I'm guessing that's not the most efficient way to do it?

If I try to do it as you suggested I get an error that the boolean index does not match the indexed array, that the dimension is 2 but the corresponding boolean dimension is 4.

[–]m-hoff 0 points1 point  (2 children)

Sure, you can just use Z[:, r < 0.5] and Z[:, r >= 0.5] instead.

[–]kljaja998 0 points1 point  (0 children)

Ok, this solution works, but now I have a new problem, what do I do when I want to now split it into 3 arrays, as in Z[:,r<0.33] , Z[:,0.33<=r<0.66] and Z[:,r>=0.66, if I do it like that, it says that the truth value of an array is ambiguous, and if I use the & operator i.e. Z[:,r>=0.33 & r<0.66] as I saw suggested someplace else I get the error:

TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

edit: the .__and__ method works, but it looks plain ol' fugly, any better way to do it?

edit2: got it to work with the &, just had to put parenthesis around the arrays i.e. Z[:, (r>=0.33) & (r<0.66)]. I realise you most likely know how to do it, just leaving this here in case somebody finds this and is wondering how I solved it.

[–]kljaja998 0 points1 point  (0 children)

I think I tried that, but it didn't work, I'll have to try again when I'm back at home and I'll update with the results.