Learn practical skills, build real-world projects, and advance your career

NUMPY ARRAY OPERATIONS

Functions

Numpy is a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices along with a large collection of high-level mathematical functions to operate on these arrays. Moreover Numpy forms the foundation of the Machine Learning stack.

  • where()
  • nonzero()
  • flip()
  • average()
  • mean()
import numpy as np
function1 = np.where()
function2 = np.nonzero()
function3 = np.flip() 
function4 = np.average()
function5 = np.mean()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) /tmp/ipykernel_35/3789970168.py in <module> ----> 1 function1 = np.where() 2 function2 = np.nonzero() 3 function3 = np.flip() 4 function4 = np.average() 5 function5 = np.mean() <__array_function__ internals> in where(*args, **kwargs) TypeError: where() missing 1 required positional argument: 'condition'

Function 1 - np.where()

Numpy's np.where() returns elements chosen from x or y depending on condition.
Syntax : numpy.where(condition,x,y)

# Example 1 -
a = np.arange(10)
np.where(a < 5, a, 10*a)
array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])