Recipe: How to select elements from Numpy array in Python?
DATA MUNGING DATA CLEANING PYTHON

How to select elements from Numpy array in Python?

This recipe helps you select elements from Numpy array in Python
In [1]:
## How to Select Elements from a Numpy Array
def Kickstarter_Example_3():
    print()
    print(format('How to Select Elements from Numpy Array', '*^52'))

    # Load library
    import numpy as np

    # Create row vector
    vector = np.array([1, 2, 3, 4, 5, 6])
    # Select second element
    print()
    print(vector[1])

    # Create matrix
    matrix = np.array([[1, 2, 3],
                   [4, 5, 6],
                   [7, 8, 9]])
    # Select second row, second column
    print()
    print(matrix[1,1])

    # Create Tensor
    tensor = np.array([
                    [[[1, 1], [1, 1]], [[2, 2], [2, 2]]],
                    [[[3, 3], [3, 3]], [[4, 4], [4, 4]]]
                  ])
    # Select second element of each of the three dimensions
    print()
    print(tensor[1,1,1])
Kickstarter_Example_3()
******How to Select Elements from Numpy Array*******

2

5

[4 4]


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from eClerx
1 developer from MudraCircle
1 developer from YASH Technologies
1 developer from Altimetrik
1 developer from HvH
1 developer from New Delhi DataPoint
1 developer from ANAC
1 developer from KPMG
1 developer from Renovite Technologies
1 developer from Bank of America