Python numpy arrays

numpy is a package that contains several classes, functions, variables etc. to deal with scientific calculations in Python. numpy is useful to create and also process single and multi-dimensional arrays. In addition, numpy contains a large library of mathematical functions like linear algebra functions and Fourier transforms.

Install numpy arrays

To work with numpy, we should first import numpy module into our Python programs as:

import numpy

we can use any of the objects from that package. But, to refer to an object we should use the format:numpy.object .

Installing numpy

pip install numpy

Python numpy arrays

creation of numpy array examples:

Python program to create a simple array using numpy.

CopiedCopy Code

import numpy
arr = numpy.array([10, 20, 30, 40, 50]) 
print(arr)

Second version of Program to create an array.

CopiedCopy Code

import numpy as np 
arr = np.array([10, 20, 30, 40, 50]) 
print(arr)

Third version of Program to create an array.

CopiedCopy Code

from numpy import * 
arr = array([10, 20, 30, 40, 50]) 
print(arr)

Creating arrays in numpy can be done in several ways. Some of the important ways are:
  1. Using array() function
  2. Using linspace() function
  3. Using logspace() function
  4. Using arange() function
  5. Using zeros() and ones() functions