Issue
I'm very new in Python and in Numpy. In fact, I'm just learning.
I'm reading this tutorial, and I got stuck in these lines :
>>> x = np.arange(30).reshape(2,3,5)
>>> x
array([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]],
[[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]]])
>>> b = np.array([[True, True, False], [False, True, True]])
>>> x[b]
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]])
I can't understand how we have come up with the result of x[b].
I also try to guess the result of x[[False, False, False, True]]
Please explain to me, I'm a very newbie.
Solution
You have 3 arrays in 1 array:
[
[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]
]
With your following line: b = np.array([[True, True, False], ...])
you say that you want to keep the first 2 rows (the first 2 True values) and that you don't want the last row (the last False value).
The other part works the same way, you have 3 arrays in 1 array:
[
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[25, 26, 27, 28, 29]
]
And your line b = np.array([..., [False, True, True]])
says to not keep the first row (because first value is False) but that you want to keep the two last lines (2 last values are True).
Answered By - Stanko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.