Posts

Showing posts with the label numpy

Python Numpy Tutorial #2

Image
In our last tutorial, we talked about numpy arrays. If you have not read it, visit  here.   In this post, we will deeper into numpy and talk a bit about the various tools it provides us.  At first, we will see how arithmetic operations work in numpy arrays and the numpy universal functions, ending this tutorial with broadcasting. Array Maths: Basic element-wise addition, subtraction, multiplication, and division can be done in this way : import numpy as np x = np . array([[ 1 , 2 ],[ 3 , 4 ]]) y = np . array([[ 5 , 6 ],[ 7 , 8 ]]) print (x + y) #element-wise addition print (x - y) #element wise subtraction print (x * y) #element-wise multiplication print (x / y) #element-wise division #For all these operations, the first operand will be from x and the second operand from y The output will be an array of the operation on the two vectors. The dot product of two matrices can be calculated in the following way: import numpy as np x ...

Python Numpy Tutorial #1

Image
Numpy is the major library for scientific computing in Python.NumPy enriches the programming language Python with powerful data structures for efficient computation of multi-dimensional arrays and matrices. If you are familiar with Octave or Matlab, you will find this tutorial easy. NB: Numpy can be imported using import numpy as np  Arrays : You can create an array as follows: a = np . array([ 1 , 2 , 3 , 4 ]) #creates a 1x 4 array b = np . array([[ 1 , 2 , 3 ],[ 1 , 2 , 3 ]]) #creates 2x3 array Along with the array, some important parameters taken by np.array ()  are:    1. dtype: It helps you to pass the desired datatype of the array. The       permitted  datatypes are -> int8, int16, int32, int64, float16, float32, float64, complex64 and complex128. Int is for integers, float can store real numbers and complex can store complex numbers. The number represents the bit of data stored...