Whether you are a professional and have been working with Python for quite some time or you are a fresher and have just started using python, you must have heard of NumPy, a python library for numerical operations. It is extensively used but regardless of how popular it is, wouldn’t you agree that it’s practically not possible to know all the commands and operations by heart? Sometimes you just have to turn to internet to look up even the most basic things. Don’t worry, no judgments here, we all have done it.
We, at Intellipaat understand that this happens more often than not and that is exactly why we have come up with this NumPy cheat sheet for our learners, in case they need a quick reference for NumPy.
This cheat sheet has been designed assuming, one has basic python knowledge and will provide you with all the basics that you need to get started with NumPy in Python.
It is a library consisting of multidimensional array objects and a collection of routines for processing those arrays. NumPy has put python lists out of the job as NumPy arrays are more efficient, convenient and makes it faster to read or write an item.
Using NumPy, mathematical and logical operations on arrays can be performed. NumPy also provides high performance.Some of the key features that contribute in the popularity of NumPyare:
Since NumPy is a Python Library, it has to be imported first before you start using NumPy. To import NumPy, type in the following command:
An NDarray in numpy is a space efficient multi-dimensional array which contains items of same type and size. It provides vectorized arithmetic operations.
Just knowing what a NumPy array is not enough, we need to know how to create a Numpy array. You can create a NumPy array in the following ways:
When you have the data you need to import to python, you can use NumPy to convert that data into NumPy arrays but sometimes when you don’t initially have any data or when you are starting from scratch and need an empty array you can use later then you can use numpy.zeros() function.
You can create empty arrays in following ways:
[[0., 0., 0., 0.],
[0., 0., 0., 0.]],
[[0., 0., 0., 0.],
[0., 0., 0., 0.]]])
Next comes, how to save or load an array or a file in NumPy
NumPy offers a few numbers of what we call ‘properties of NumPy array’ which can be used to check the nature of the array, that is, what kind of elements it contains or what is the size,etc.
Following are some mathematical operations you can perform using NumPy arrays:Note: While performing arithmetic operations in NumPy arrays, you should make sure that the items are of same shape.
There are some array shape manipulation operations present in NumPy. Following is the list of such operations with their respective commands and syntax:
Following is a set of functions in NumPy that operate on NumPy arrays:
We have covered all the basics of NumPy in this cheat sheet. If you want to start learning NumPy in depth then check out the Python Certification Training by Intellipaat. Not only will you get to learn and implement NumPy with a step by step guidance and support from us, but you will also get to learn some other important libraries in python such as SciPy, NumPy, MatPlotLib,Scikit-learn, Pandas, Lambda function and more. You will also get 24*7 technical support to help you with any and all of your queries, from the experts in the respective technologies here at intellipaat throughout the certification period. So, why wait? Check out the training program and enroll today!Previous Next
Learn SQL in 16 hrs from experts