NumPy follows standard 0 based indexing.
Given array : 1 13 6 9 4 7 19 16 2 Input: print(NumPy_array_name[ :,2]) # printing 2nd column Output: [6 7 2] Input: x = NumPy_array_name[ :,1] print(x) # storing 1st column into variable x Output: [13 4 16]
Method #1: Selection using slices
For column : numpy_Array_name[ : column,]
For row : numpy_Array_name[ row,: ]
printing array as it is [[ 1 13 6] [ 9 4 7] [19 16 2]] printing 0th row [ 1 13 6] printing 2nd column [6 7 2] selecting 0th and 1st row simultaneously [[ 1 13] [ 9 4] [19 16]]
Method #2: Using Ellipsis
For column : numpy_Array_name[…,column]
For row : numpy_Array_name[row,…]
where ‘…‘ represents no of elements in the given row or column
Note: This is not a very practical method but one must know as much as they can.
printing array as it is [[ 1 13 6] [ 9 4 7] [19 16 2]] selecting 0th column [ 1 9 19] selecting 1st row [9 4 7]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Create a DataFrame from a Numpy array and specify the index column and column headers
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- How to access different rows of a multidimensional NumPy array?
- Program to access different columns of a multidimensional Numpy array
- Python - Extract ith column values from jth column values
- Get column index from column name of a given Pandas DataFrame
- Python - Numpy Array Column Deletion
- Python | Numpy numpy.resize()
- Python | Numpy numpy.transpose()
- Python | Numpy numpy.ndarray.__lt__()
- Python | Numpy numpy.ndarray.__gt__()
- Python | Numpy numpy.ndarray.__le__()
- Python | Numpy numpy.ndarray.__ge__()
- Python | Numpy numpy.ndarray.__eq__()
- Python | Numpy numpy.ndarray.__ne__()
- Python | Numpy numpy.ndarray.__neg__()
- Python | Numpy numpy.ndarray.__pos__()
- Python | Numpy numpy.ndarray.__truediv__()
- Python | Numpy numpy.ndarray.__mul__()
- Python | Numpy numpy.ndarray.__sub__()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.