NumPy Maths

Python NumPy provides basic maths operations and functions with arrays.

Arithmetic operation with arrays

  1. NumPy arrays can have arithmetic operations. In example below, we can add a value of 1 to all the elements of array.

The above code will output this result

[3 4 6 8]

[ 2 4 8 12]

[0.5 1. 2. 3. ]

[ 0.84147098 0.90929743 -0.7568025 -0.2794155 ]

[ 2.71828183 7.3890561 54.59815003 403.42879349]

[1.09861229 1.38629436 1.79175947 2.07944154]

[1. 1.41421356 2. 2.44948974]

[ 1 4 16 36]

More functions on arrays

There are many more functions that be performed using numpy. In example below, we are creating a two dimensional array and then performing some useful functions.

The above code will output this result

[[0 1 1 0 1 1]
[1 1 0 1 1 0]
[1 0 0 1 1 0]
[0 1 1 0 1 0]
[1 0 1 1 1 1]
[1 0 1 1 1 1]
[0 0 1 1 1 0]
[1 0 0 1 0 0]
[0 0 0 0 0 1]
[1 0 1 0 1 0]]

33
0
1
60
[4 4 3 3 5 5 3 2 1 3]
0.55
0.49749371855331
1.0
[0 1 1 0 1 1 0 0 0 1]