How to Choose a Multi-Dimensional Array in Python

Asked 2 years ago, Updated 2 years ago, 130 views

I am using Python 3.6.

when np.array gives the array and range below arr[a][b][c][d]
a--1 to 72
b--0 to 11
c--0 to 9
d--0 to 4500
I'd like to substitute arr1 in this way.

arr1 = arr [All (1-72)] [One from 12] [All (0-9] [All (0-4500]

How can I do it?

python python3 array numpy

2022-09-30 17:55

1 Answers

NumPy extends Python subscript notation, and if you want to take all the elements on an axis, you can take them by specifying :.

Example Execution:

>>import numpy as np
>>arr=np.zeros (72, 12, 10, 4501)
>>arr.shape
(72, 12, 10, 4501)
>>arr1=arr[:,5,:,:]#Try the fifth line.
>>arr1.shape
(72, 10, 4501)

For more information, see the Indexing in the NumPy document.


2022-09-30 17:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.