It is a memorandum. It's easy to forget how to retrieve multiple arrays with slice in python, so I'll leave it for you.
arr2d = np.array([[5, 10, 15], [20, 25, 30], [35, 40, 45]])
This will create the following multiple array: ([[ 5, 10, 15], [20, 25, 30], [35, 40, 45]])
From this, the upper right [10, 15] [25, 30] I would like to take out.
I think there are various methods, but
arr2d[:2, 1:]
You can take it out with. Explained below.
arr2d[:2]
Where is the part that can be taken out with? This means that the row of arr2d is fetched up to one before index 2.
In other words ([[ 5, 10, 15], [20, 25, 30]])
Is taken out.
Then take the column from the above matrix.
The completed form is
arr2d[:2, 1:]
However, the point to pay attention to here is [1:].
If you omit the ending index, you can retrieve from index 1 to the end. Since the column is specified here, it is retrieved
([[10, 15], [25, 30]])
It will be.
In a multidimensional array array, array [n, m] is an image of first specifying a row with n and then narrowing it down with m !!
If the start index is omitted, the slice is extracted from the beginning to before the end index.
On the other hand, remember that if you omit the end index, the start index to the end will be extracted.
that's all.
Recommended Posts