(Disclaimer: Yes, I know, in a perfect world I should avoid working with jagged arrays in numpy altogether... The following are some questions regarding toy example that are all related to jagged arrays and that I don't understand.)
1] Consider
my_array_1 = np.array([
[np.array([[0,0],[0, 0],[0,0]]),np.array([0,0,0])],
[np.array([0,0,0]).reshape(0,0),np.array([0])]
])
For some reason, this np.equal(NN_z,NN_z)
throws an error
The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().
The only way to get it to work is to loop through the array and compared each subarray individually. Is there a more elegant solution?
2] np.array([[[1,2,3],[2,2,2]], np.array([5,2])])
evaluates finde, but making a very small change and giving the np.array
constructor ndarrays
instead of lists (but with the same elements), somehow doesn't work anymore: np.array([np.array([[1,2,3],[2,2,2]]), np.array([5,2])])
, giving the error
ValueError: could not broadcast input array from shape (2,3) into shape (2)
What is going on here?
3] In this answer a sequence of examples of jagged arrays was provided and how np.array
fails on them. I'm not asking you to go through all of them, but rather to give me some insight: Is it even possible to discern some general rule how np.array
works for jagged arrays?