Numpy Arrays : Computations

Its quite common to assume that Numpy Arrays behave like normal arrays in python except few exceptions, but since numpy array is designed to work on large and complex data sets, the designers of numpy build universal functions for operations on Numpy Arrays.

Univeral functions also known as vectorized operation, improves and optimizes runtime performance. Its the right way to work on large numerical sets.

Array arithmetic

A numpy array can be treated as a variable and following operations can be performed

  • Addition : x + n
  • Subtractions : x – n
  • Multiplication : x * n
  • Division : x / n
  • Floor Division : x // n
  • Exponential : x ** n
  • Modulus : x % n
Arithmetic operators implemented in NumPy

Operator

Equivalent ufuncDescription
+np.add Addition(e.g., 1 + 1 = 2)
np.subtract Subtraction(e.g., 3 – 2 = 1)
np.negative Unary negation(e.g., -2))
*np.multiply Multiplication(e.g., 2 * 3 = 6))

/

np.divide Division(e.g., 3 / 2 = 1.5))

//

np.floor_divide Floor division(e.g., 3 // 2 = 1) )

**

np.power Exponentiation(e.g., 2 ** 3 = 8) )
%np.mod Modulus/remainder

(e.g., 9 % 4 = 1))

Besides Arithemetic operations, Numpy supports, trignometric functions, Absolute value, Algorithmeic fucntions

A detailed list can be found here : https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.math.html

 

 

Phone: 512-539-0390
NJ Training Academy Inc , 405 Dry Gulch Bend
Cedar Park, Texas, 78613