Working with Numpy array in Python Part-1
Python is the most popular general purpose programming language used in machine learning, data science, web application etc. Python has so many packages for machine learning, data-science and data analysis like, Matplotlib, Pandas, SciPy, Tensor-Flow, Keras etc. One of the basic package is Numpy.
Numpy is the basic package to manipulate data in Python. Numpy provides support for large, multi-dimensional arrays, various derived objects(such as masked arrays and matrices), for scientific calculation in linear algebra and matrices.Numpy is largely used in all machine-learning packages like Matplotlib, Pandas, SciPy, Tensor-Flow, Keras etc.
Numpy is not preinstalled with Python. You have to install Numpy addtionally. In this article, we will discuss about installation and how to use Numpy.
Linux and Mac users can directly install Numpy with pip command. You can also check this article how to work with pip.
pip install numpy
To Install Numpy in Windows system, download Anaconda which is open-source distribution of the Python and R programming languages including Numpy and many popular packages.
You can check if Numpy is installed correctly by running bellow command. It will display all your pip installed packages.
How to Use?
Whenever you want to use Numpy in your script, first import Numpy module in above the script.
import numpy as np
Now you can use all Numpy functions. Lets first create simple Numpy array. For that first create file
index.py file and put bellow code which will print array variable.
import numpy as np # create numpy array x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # print array print(x)
Now go to Terminal in the file location and run script with bellow command.
This way, you can run Python script from your Terminal. In the next part, we will discuss on Basic functions to create and manipulate Numpy array.
Copyright 2023 HackTheStuff