3...2...1...Happy New Python!

3...2...1...Happy New Python!


Happy New Year! To all the readers, may this year bring you love, wisdom, health, and success! We are entering the year 2020 and Python is entering the 31st year. It is as happening as it can be.

This is my 5th blog in "Let's Talk Python" and in am very glad to announce that we have covered Numpy, Pandas, and many other modules in python which I shall be discussing soon. This article is going to be entirely dedicated to Numpy.

Numpy is an extension to the python programming language, adding support for large, multidimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

Numpy, python, etc are like those small bones and joints without which a snake as python cannot coil any of its prey. Well, if it can't coil... What's python about it?

Without wasting any more time...let's start this article.

Let's begin with, "What are Multidimensional arrays? And why do we need them?"

Multidimensional arrays are used to store data in a matrix form, or a tabular form. To say, what are the dimensions of your room? The answer is height, Length, and breadth. Simple!

Now, a single array will store values for a single room only. But what if you have a penthouse? Won't it be a shame that despite having so many rooms you can use ...only one? Well, multidimensional arrays are here to rescue. An N-d array can store the dimensions of each room in it. That means now you can access each room of your home wholeheartedly.

They can be used to store the values of the railway schedule, tabular data. Etc.

Consider the following image to know what exactly these multidimensional arrays are.


No alt text provided for this image

 

A 1D array stores values in a row. That means, either height, or breadth, or length of all your rooms.

A 2D array stores values in rows and columns. That means any pair out of height, length, and breadth.

Now, a 3D array stores values in rows, columns, and depths. That means it will have all the three required dimensions stored for all rooms.

How to create a Numpy array in python?

See the image below:

No alt text provided for this image

We can simply pass a list through numpy’s inbuilt array function arr=np.array(list).



What are some of the methods used in arrays?


No alt text provided for this image

The arr.arange() is a built in function of python that works as a range and returns an ndarray.

The arr.min() prints the minimum value in the array.

The arr.max() prints the maximum value passed in the array.

The arr.all() and arr.any() check for conditions where arr.all() works as “&” and arr.any() works as “|”.

 

Aside from this, we studied about views and copies.

To save memory, python creates a view of two arrays pointing at the same location. That means, it will show up as two arrays that are a copy of each other but in actual they are a view of the same location.

Deep Copy & Shallow copy

There are two ways we can copy in python. They are shallow and deep.

In a deep copy, a new collection of objects is made. All the objects of the original are copied and put in here. So, any changes done to the copy do not change anything in the original. 

        

 

No alt text provided for this image

In shallow copy, a new collection of objects in made but objects are filled with references to the original. So, any changes done to the copy do change things in the original.

             

 

No alt text provided for this image

Aside from this, the following arithmetical functions can also be performed here:


 

Well! You can see, we can divide, multiply, add, subtract, find power of etc

These all functions can be performed on arrays.


Numpy provides us with many functions such as average, mean, median, mode, etc. This extension has a huge value for the mathematical understanding of any data. And we all know, maths is accurate.







Numpy and pandas together are required by data analysts for data visualization. So, it becomes necessary to master these two libraries. After this, we paced forward towards pandas that I shall be discussing in my next blog. I hope this blog was worth a while for you. Stay tuned to know what makes pandas so interesting. Let's Talk Python.

要查看或添加评论,请登录

Rohit S ModGil的更多文章

  • What and why is a Convolutional Neural Network?

    What and why is a Convolutional Neural Network?

    "Wow, your shoes look amazing!" "I love that black tie on you." "Those squared goggles do not suit your oval face".

    1 条评论
  • Gradient Descent in the Real-world

    Gradient Descent in the Real-world

    Do you see the Ape in the image? Well, the ape is blind and to add more, it is famished. It wants to eat that banana…

  • Data visualization in python

    Data visualization in python

    Data analysis is about understanding and interpreting the loads and loads of data that is being collected worldwide to…

  • OOPS! Python!

    OOPS! Python!

    Well, here I am with my 4th blog in "Let's talk python". Due to my exams, I was quite busy and thus couldn't upload any…

    2 条评论
  • Python: An exceptional language

    Python: An exceptional language

    This is my third blog in “Let’s talk Python”. I am grateful to Shoolini University for providing me with such an…

    4 条评论
  • Enumerate with Python

    Enumerate with Python

    I am here again to talk python. This week we learnt data structures and functions that are used in python.

  • Python: The Master Programming Language

    Python: The Master Programming Language

    I am Rohit S Modgil. Under Shoolini University’s AI-ML Super 20 program, I am starting my journey to learn python for…

社区洞察

其他会员也浏览了