I’m beginner in Python & Numpy. Most tutorials I found seems for expert without really explaining the basic of it.
Even understanding what axis represents in Numpy array is difficult.
I have to read few tutorials and try it out myself before really understand it.
I will update it along with my growing knowledge.
1. Numpy Array Properties
1.1 Dimension
Important to know dimension because when to do concatenation, it will use axis or array dimension.
Row – in Numpy it is called axis 0
Columns – in Numpy it is called axis 1
Depth – in Numpy it is called axis 2
Python Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import numpy as np # Array with 1 dimension A = np.array([1]) B = np.array([1,2]) print("A: ", A) print("A dimensions: ", A.ndim) print("B: ", B) print("B dimensions: ", B.ndim) # Array with 2 dimensions C = np.array([[1,2], [3,4], [5,6]]) print("C: ", C) print("C dimensions: ", C.ndim) # Array with 3 dimensions D = np.array([[[1,2], [3,4], [5,6]]]) print("D: ", D) print("D dimensions: ", D.ndim) |
Output
1 2 3 4 5 6 7 8 9 10 11 12 |
A: [1] A dimensions: 1 B: [1 2] B dimensions: 1 C: [[1 2] [3 4] [5 6]] C dimensions: 2 D: [[[1 2] [3 4] [5 6]]] D dimensions: 3 |
Snippet
References
https://www.datacamp.com/community/tutorials/python-numpy-tutorial
https://www.oreilly.com/library/view/elegant-scipy/9781491922927/ch01.html