NumPy, which stands for Numerical Python, is a library consisting of multidimensional array objects and a collection of routines for processing those arrays. Using NumPy, mathematical and logical operations on arrays can be performed.
In Numpy, number of dimensions of the array is called rank of the array.A tuple of integers giving the size of the array along each dimension is known as shape of the array. An array class in Numpy is called as ndarray. Elements in Numpy arrays are accessed by using square brackets and can be initialized by using nested Python Lists.
- Mathematical and Logical Operations
- Fourier Transform
- Operation related to linear Algebra
In this one specifies dtype to define the size. It uses fewer bytes therefore less memory. No type checking while iterating through the object.
- Mathematical
- Plotting
- Backend(Pandas, photography)
- Machine Learning
- Python Structure (List, Tuple)
- Numpy array creation object (ones, zeros, linspace, arange)
- Reading from disk
- Array from bytes
- Special Library Function (random)
Need to explain the logic while using it as it is less readable.
In this lesser the dtype more speed factor is gained i.e. np.int8>>>>np.int64
Strides - Number of bytes in each dimension while traversing. E.g. in 3X3 matrix with itemsize = 2 then stride is 6.
In this all elements share the same computation time while processing. There is no specific time for a particular step.
E.g. Game of Life
It is very easy to compute, but it can take a very long time because you need to ensure a given number does not diverge.
E.g. Mandelbrot
Elements share the same computation time but in subgroups.
E.g. Boids(Flock of birds):- separation, alignment, cohesion
- The copy owns the data and any changes made to the copy will not affect original array, and any changes made to the original array will not affect the copy.
- The view does not own the data and any changes made to the view will affect the original array, and any changes made to the original array will affect the view.
- Numpy Expression
- Cython (Optimized Static Compiler)
- Numba (Speed as written in Python)
- Theano (Optimized, speed, stability, GPU)
- PyCUDA (Access CUDA Parallely)
- PyOpenCL (Access GPU and Massive Parallel)
In np.hsplit and np.vsplit we need to define the parameter that divides the array in equal parts otherwise throw error. In np.split it will divide the array and make empty array if split divide is more that elements along particular axis.
-
For 1-D —>
axis = 0 -
For 2-D —>
Axis = 0 down the column
Axis = 1 along the row
np.dtype()
np.pad()
: The function returns the padded array of rank equal to the given array and the shape will increase according to pad_width.np.diag()
: Diagonal we require; k>0 means diagonal above main diagonal or vice versa.defaults = np.seterr(all="ignore")
: remove all warning.np.fromiter()
: array using generatornumpy.tile(A, reps)
: Construct an array by repeating A number of times given by reps.np.add.reduce()
: to add array faster than np.sum() for small array.data.flags.writeable = True
: to make data in readable format.np.iinfo, np.finfo
: limit the machine to integer and float. The kind of integer data type to get information about.numpy.set_printoptions(threshold=sys.maxsize)
: to print all the valuesnp.put()
: used to change values defining data amd indexnp.random.choice
: used to select number of random values.keepdims parameter
: used to maintain dimensions on np operation like mean etc