Saved Bookmarks
| 1. |
How is arr[:,0] different from arr[:,[0]] |
|
Answer» arr[:,0] - Returns 0th index elements of all rows. In other words, return the first column elements. import numpy as nparr = np.array([[1,2,3,4],[5,6,7,8]]) new_arr =arr[:,0] print(new_arr) Output: [1 5]arr[:,[0]] - This returns the elements of the first column by adding extra dimension to it. import numpy as nparr = np.array([[1,2,3,4],[5,6,7,8]]) new_arr =arr[:,[0]] print(new_arr) Output: [[1][5]] |
|