Python NumPy Learn NumPy Arrays With Examples

Python NumPy Learn NumPy Arrays With Examples


Python NumPy

  • What is NumPy?
  • What are NumPy Arrays?
  • Where is NumPy used?
  • How to install NumPy?
  • Python NumPy Operations


What is NumPy?

NumPy is a Python package that stands for ‘Numerical Python’, NumPy is a library for the Python programming language, Python NumPy is a package or library for scientific mathematical operations or computations also NumPy add large support for Arrays and Matrices with different operations. also, NumPy have some features like:
  • Multi-dimensional array
  • Methods for processing arrays
  • Element by element operations
  • Mathematical operations like linear algebra 


What is NumPy Arrays?

Numpy array is a robust N-dimensional array object which is in the form of rows and columns. We can initialize Python NumPy arrays from nested Python lists and access its elements. In order to perform these NumPy operations. Using Python NumPy we can create one dimensional as well as multi-dimensions arrays and also we can perform various operation on these arrays

How to install NumPy?

To install Python NumPy, go to your terminal or cmd and hit this command “pip install NumPy”. Once the installation is completed, write a simple python program to check NumPy is installed or not just do import it by typing: “import NumPy as np”.
pip install NumPy
import numpy as np 
a=np.array([1,2,3]) 
print(a)
Output: [1,2,3]


Python NumPy Operations:

  • itemsize
We can calculate the byte size of each element.
import numpy as np 
a=np.array([(1,2,3)]) 
print(a.itemsize)
Output: 4

  • ndim
Used to find the dimension of the array, whether it is a two-dimensional array or a single-dimensional array

import numpy as np 
a=np.array([(1,2,3)]) 
print(a.ndim)
Output: 1

  • dtype
Used to find the data type of the elements that are stored in an array.
import numpy as np 
a=np.array([(1,2,3)]) 
print(a.dtype)
Output: int32

  • size
Used to find size of an array
import numpy as np 
a=np.array([(1,2,3)]) 
print(a.size)
Output: 3

  • max
Used to find maximum value from NumPy arrays.
import numpy as np 
a=np.array([(1,2,3)]) 
print(a.max())
Output: 3

  • min
Used to find minimum value from an array.

import numpy as np 
a=np.array([(1,2,3)]) 
print(a.min())
Output: 1

  • sum
Used to add array elements or sum returns additions of NumPy arrays.
import numpy as np 
a=np.array([(1,2,3)]) 
print(a.sum())
Output: 6


These are basic Python NumPy operations, there are so many operations are available. 




Comments