Numpy n dimensional Arrays ( ndarray )

NumPy (Numerical Python) is a popular open-source Python library used for numerical computing and data analysis.

NumPy is often used in combination with other Python libraries, such as Pandas, Matplotlib, and Scikit-learn, to create a complete data analysis ecosystem in Python.

Some of the key features of NumPy :

  1. Fast vectorized operations: NumPy allows you to perform operations on entire arrays rather than looping through each element, which can be much faster.
  2. Broadcasting: NumPy allows you to perform operations between arrays with different shapes and sizes, which makes it easy to perform operations on data that is not the same shape.
  3. Linear algebra: NumPy provides a suite of functions for performing linear algebra operations such as matrix multiplication, eigenvalues, and eigenvectors.
  4. Random number generation: NumPy includes tools for generating random numbers, which are useful for simulations and statistical analysis.
Axis of Two dimensional array Numpy is used scientific computing with Python.
We can create powerful multidimensional arrays using Numpy.
Numpy requires all elements are to be of same data type. ( This is the main difference with Pandas which can accommodate different data types. )

Installing Numpy

Use in your command prompt or the environment you are using .
pip install numpy
After installation you can add this line to import Numpy inside Python program.
import numpy as np
Getting the Numpy version installed in your system.
import numpy as np
print("Numpy Version : ",np.__version__)

Creating Numpy Array

import numpy as np
print(npr) # [4,5,9]

l1=[3,2,8] # List 
npr=np.array(l1) # Using List to create np array
print(npr) # [3,2,8]

t1=(8,12,1) # Tuple 
npr=np.array(t1) # from tuple to np array 
print(npr) # [ 8 12  1]

Numpy installation and creating array at Colab platform using List Tuple and checking the version


NumPy ArrayScientific computing with Python
appendAdding Data to array at the end
insertAdding Data to array at the given index position
dtypeData types of Numpy array
Array MethodsMethods to get result ( output ) using NumPy
array_split()break the array to get sub-arrays
bincountfrequency of occurrence of elements
whereReturn elements depending on condition check
shapeReturn shape of the array
reshapeChange the array shape and dimension

Creating array

createCreating array using Numpy
eyearray with ones and zeros
emptyarray without initializing entries
empty_likearray of same shape and type
fullArray filled with input value
onesarray filled with ones
arangecreating array of fixed steps
linspacecreating array of fixed number
zerosAray filled with zeros
ExerciseCreating different types of array

random.randitRandom integers with lower and upper limits and size
random.randUniform distribution [0,1] of random numbers of given shape & population
random.randnNormal distribution of random numbers of given shape & population
random_sampleContinuous uniform distribution over an interval

sum()Sum of elements, or along the axis
mean()Mean value of elements, or along the axis
max()Maximum value among elements, or along the axis
min()Minimum value among elements, or along the axis
std()Standard deviation along the axis
Exercise aBasics of Creating Arrays
math functionsNumpy math functions
Get the list of all functions of Pandas. ( Use dir() )
import numpy as np
print(len(dir(np))) # 622
List of functions
for i in dir(np):

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer