We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental level, click here for more details.

In addition to simply using indexing to select elements from a Numpy array, Python lets you easily use conditional tests to systematically select parts of a Numpy array. In the following example, elements less than 0.8 from a two-dimensional array is selected via a conditional test inside the brackets, and the returning result is a one-dimensional array.

#import Numpy module
import numpy as np
#create an array of shape 3,2
T = np.random.random((3, 2))
T
#output
array([[0.39818887, 0.09905403],
       [0.62459552, 0.34570658],
       [0.25420698, 0.9049677 ]])
#select element of array, with condition less than 0.8
T[T < 0.8]
#result
array([0.39818887, 0.09905403, 0.62459552, 0.34570658, 0.25420698])

You can also watch videos on our YouTube channel for more understanding of Python programming skills.


0 Comments

Leave a Reply

Avatar placeholder