NumPy array basics
|
Creates a 1D array with values 1, 2, 3. (shape 1x3) |
np.array([(1,2,3), (4,5,6)])
|
Creates 2D array of shape 2x3 with values 1,2,3,4,5,6 |
np.array([[(1,2,3), (4,5,6)], [(7,8,9), (10,11,12)]])
|
Creates a 3D array with shape 2x2x3 |
|
Creates a 3x4 array of zeros |
|
Creates a 1D array of values 1 through 60 at steps of 5 |
|
Reshapes array a
into an array of shape 2x3x4 |
|
To get the shape of the array a
|
Subsetting
|
Gets the 0th element in 1D array a
|
|
Gets the 0th element in 2D array b
|
|
Gets the 0th element in 3D array c
|
|
Gets the element which is the 0th element in the 0th row in the 9th depth |
Slicing arrays
1D arrays |
|
Selects everything |
|
Selects the 2nd through the 4th rows (does not include the 5th row) |
2D arrays |
|
Selects all rows and all columns |
|
Selects all rows, and the zeroth column |
|
Selects the zeroth row, and all columns in that row |
|
Selects the zeroth and first row, but NOT the second. It includes all the columns in that row |
|
Selects the zeroth and first row, and the zeroth and first column |
3D arrays |
|
Selects all rows and columns on all depths |
|
Selects the everything in the first depth |
|
Selects the first row of each depth |
|
Selects the first column of each depth |
|
Created By
Metadata
Comments
Niti, 08:59 2 Aug 20
Its very helpful
Add a Comment