Last answered:

10 Oct 2022

Posted on:

05 Nov 2021

0

Axis clarifiction on np.delete

earlier we deal with column as axis = 0 and row axis = 1, so why here when we want to delete column we specified the axis = 1?

1 answers ( 0 marked as helpful)
Posted on:

10 Oct 2022

0

Axis = 0 does not mean literally to deal with rows and the same applies for axis = 1 in columns
However,
Axis = 0 means that we are going to apply the function vertically (from top to bottom)
- For example, np.sum([[1, 1, 1], [2, 2, 2]], axis=0) means that we will aggregate vertically resulting only in one row so the result will be in this case array([3, 3, 3])
- The same applies for np.delete, it means that we will delete starting from top (deleting a row)

By the same technique, you can understand axis=1 which means that we should apply the function horizontally (from left to right)
- For example, np.sum([[1, 1, 1], [2, 2, 2]], axis=1) means that we will aggregate horizontally resulting only in one column so the result will be in this case array([3,6])
- The same applies for np.delete, it means that we will delete starting from left (deleting a column)

Submit an answer