Numpy

Sidhant Suryavansham
2 min readDec 10, 2020

NumPy is a python library, and it’s used for working with arrays.

It provides a high-performance multidimensional array object, and tools for working with these. arrays.it’s also provide many function to create arrays

it’s written partially in Python, but most of the parts that require fast computation are written in C or C++.

How to Install NumPy

If you have Python on your system and PIP already installed on a system, then you can easily install numpy .

Install it using this command:

fig 1.0: Command prompt window

If this command fails in your system , then use a python distribution already has NumPy installed like, Spyder ,Anaconda etc.

Import NumPy

After the installation of NumPy , import it in your application by adding the import keyword:

NumPy as np

It is (numpy)usually imported under the np alias.

for Create an alias with the as keyword while importing

Import numpy as np

Creating 0-D Arrays

import numpy as np

arr = np.array(42)

print(arr)

Creating 1-D Arrays

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

print(arr)

3-D Array

import numpy as np

arr = np. array ([[[1, 3, 2], [6, 5, 4]], [[4, 5, 3], [7, 5, 6]]])

print(arr)

Check Number of Dimensions

Import numpy as np

b = np.array([1, 2, 3, 4, 5])

print(b.ndim)

Access Array Elements

We can access an array element by referring to its index number.

import numpy as np

arr = np.array([1, 2, 3, 4])

print(arr[0])

Access 2-D Arrays

for access elements from 2-D arrays we can use comma separated integers it’s representing the dimension and the index of the element.

Access the 2nd element on the 1st dim:

import numpy as np

arr = np.array([[1,5,3,2,4], [7,11,8,9,10]])

print(‘2nd element on 1st dim: ‘, arr[0, 1])

Conclusion

In this blog you can learn about Numpy , and how to install numpy in your system(python) ,How to use numpy like-how to create Arrays (1-D Array ,2-D Array etc.)you can also learn about how to access these array and element .

References

numpy.org

https://www.tutorialspoint.com/numpy/index.html

w3schools.com/python/numpy_intro.asp

--

--

Sidhant Suryavansham

College student , ADPYU , interested on research about new technology .