NumPy Arrays( Part II )
smart and simple
In a previous article, we have seen how we can create a numpy array manually.
In this article, we will see how we can create an array randomly, slicing of 2D array and functions related to array.
How to create an array randomly?
There are a lot of ways to create an array randomly.
- randint: It returns random integers from start to end. (start is inclusive and the end is exclusive)
we can also mention the size of an array.
let's try with rows and columns.
- rand: It creates an array of the given shape and populates it with random samples from a uniform distribution over [0, 1).
_____________________________________________________________
Slicing of a 2D array:
we have already seen the slicing concept in our article which was based on Lists in python(https://articles-dsml.medium.com/python-list-part-ii-8514a72834b7). In a 2D array, we have to slice row as well as column.
suppose we have an array
A = np.array([[10,20,30,40],
[50,60,70,80],
[90,11,12,13]])
Now I want to fetch 20 30 60 and 70 from A.
This is how you can use slicing in 2D arrays.
_____________________________________________________________
Aggregate Functions:
- sum: It returns the sum of elements in an array.
row-wise sum:
column-wise sum:
- min: It returns the minimum element from an array.
here also we can find row-wise minimum elements as well as the column-wise elements.
- max: It returns the maximum element from an array.
- mean: It returns the mean value.
In the next article, we will see functions related to linear algebra and relational operations on numpy.
Thanks for reading!!