Numpy slicing

by: mnalevanko, 9 years ago

Last edited: 9 years ago

I have a simple question regarding slicing of a numpy array.

First let's define a numpy array.

<pre class='prettyprint lang-py'>
import numpy as np
arr = np.arange(9).reshape(3,3)
</pre>

Now let's do some slicing:
<pre class='prettyprint lang-py'>
print(arr[2].shape)
print(arr[2,:].shape)
</pre>

We get the same result in both cases.
<pre class='prettyprint lang-py'>
(3,)
</pre>

Why is the result different when I change the indexing?
<pre class='prettyprint lang-py'>
print(arr[2:,:].shape)
(1,3)
</pre>

Thank you very much!



You must be logged in to post. Please login or register an account.



I am pretty noob with NumPy, I suggest asking that question here: https://www.reddit.com/r/learnpython/

-Harrison 9 years ago

You must be logged in to post. Please login or register an account.