Re:NumPy Illustrated: The Visual Guide to NumPy
by sirpunch on Tuesday December 29, 2020 @03:12AM
(#25567775)
I mean the insert and delete operations with axis value set to 0.
[ Parent
| on HN ]
Re:NumPy Illustrated: The Visual Guide to NumPy
by axi1 on Tuesday December 29, 2020 @03:44AM
(#25567935)
It probably makes more sense if you think of matrices as n-dimentional arrays: sum eliminates the n-th dimention, insert and delete increase or decrease the n-th dimension size.
Re:NumPy Illustrated: The Visual Guide to NumPy
by giu on Tuesday December 29, 2020 @04:01AM
(#25568015)
Very good point. Additionally, with insert and delete we might need to apply the rules of broadcasting [0].
For example, if I have a 2-dimensional array and I insert a scalar value by using axis=0, the scalar value needs to be broadcasted to match the column dimension of the array:
>>> a = np.array([[1,2],[3,4],[5,6]])
>>> np.insert(a, 1, 11, axis=0)
array([[ 1, 2],
[11, 11],
[ 3, 4],
[ 5, 6]])
[0] https://jakevdp.github.io/PythonDataScienceHandbook/02.05-co...