Basic Python | Numpy for Mathematical Computing


Basics of numpy and why numpy!!
A list is a collection of values. You can individually add, remove, or update these values.A single list can contain multiple data types.Though you can change individual values in a list, you cannot apply a mathematical operation over the entire list.
Numerical Python (NumPy) supports multidimensional arrays over which you can easily apply mathematical operations. We import the numpy libarary and the convert the list to numpy array and perform the mathematical operation as shown.
Numpy Overview:
Arrays can be one-dimensional, two dimensional, three-dimensional, or multi-dimensional. Look at the examples to see how the shape tuples of the arrays are used to calculate their size for x3 array, similarly we can do for 1D and 2D array.
Accessing Array Elements: Indexing
Access an entire row of an array by referencing its axis index. we can use the indices of the elements in an array to access them. You can also select a particular index of more than one axis at a time.
Accessing Array Elements: Slicing
Use the slicing method to access a range of values within an array.
Computation on Arrays: Broadcasting
NumPy uses broadcasting to carry out arithmetic operations between arrays of different shapes. In this method, NumPy automatically broadcasts the smaller array over the larger array.
Though broadcasting can help carry out mathematical operations between different-shaped arrays, they are subject to certain constraints as listed below:
When NumPy operates on two arrays, it compares their shapes element-wise. It finds these shapes compatible only if:
  • Their dimensions are the same
  • One of them has a dimension of size 1.
If these conditions are not met, a "ValueError” is thrown, indicating that the arrays have incompatible shapes.

Comparisons, Masks, and Boolean Logic

Boolean arrays are useful when you need to select a dataset according to set criteria. Here, the original dataset contains test scores of two students. You can use a Boolean array to choose only the elements that are above a given value.
Aggregations: Min, Max, and Everything In Between
NumPy provides useful mathematical functions called Universal Functions. These functions operate element-wise on an array, producing another array as output. Some of there are shown below,
Shape Manipulation
Linear Algebra
NumPy can carry out linear algebraic functions as well. The “transpose()” function can help you interchange rows as columns, and vice-versa.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.