0% found this document useful (0 votes)
7 views6 pages

NumPy: Essential Guide for Python Users

NumPy is a powerful Python library for numerical computing that supports large multi-dimensional arrays and efficient mathematical operations. It is faster and uses less memory than Python lists, making it widely used in data science and scientific computing. The document covers installation, core data structures, array types, mathematical operations, and advantages of using NumPy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

NumPy: Essential Guide for Python Users

NumPy is a powerful Python library for numerical computing that supports large multi-dimensional arrays and efficient mathematical operations. It is faster and uses less memory than Python lists, making it widely used in data science and scientific computing. The document covers installation, core data structures, array types, mathematical operations, and advantages of using NumPy.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Numpy

What is NumPy?
NumPy (Numerical Python) is a powerful Python library used for numerical
computing.

It provides support for:

Large multi-dimensional arrays

Mathematical and statistical operations

Efficient computations compared to Python lists

Why Use NumPy?


Faster than Python lists

Less memory usage

Built-in mathematical functions

Widely used in Data Science, AI, ML, and Scientific Computing

Installing NumPy

pip install numpy

Importing NumPy

import numpyas np

Numpy 1
Core Data Structure – ndarray
The main object in NumPy is the ndarray (N-dimensional array).

Creating a NumPy Array

import numpyas np

arr = [Link]([1,2,3,4])
print(arr)

Output:

[1 2 3 4]

Difference Between List and NumPy Array


Feature List NumPy Array

Speed Slower Faster

Data type Mixed Same type

Operations Limited

Memory More Less

Array Types in NumPy


1D Array

arr1 = [Link]([10,20,30])
print(arr1)

Numpy 2
2D Array (Matrix)

arr2 = [Link]([[1,2], [3,4]])


print(arr2)

Array Properties

arr = [Link]([[1,2,3], [4,5,6]])

print([Link])# number of dimensions


print([Link])# rows and columns
print([Link])# total elements
print([Link])# data type

Creating Arrays Using Built-in Functions


Zeros Array

[Link](5)

Ones Array

[Link](4)

Range of Values

Numpy 3
[Link](1,10,2)

Evenly Spaced Values

[Link](1,10,5)

Array Indexing and Slicing

arr = [Link]([10,20,30,40,50])

print(arr[0])# first element


print(arr[1:4])# slicing

Basic Mathematical Operations

a = [Link]([1,2,3])
b = [Link]([4,5,6])

print(a + b)
print(a - b)
print(a * b)
print(a / b)

Universal Functions (ufuncs)

Numpy 4
arr = [Link]([1,4,9,16])

print([Link](arr))
print([Link](arr))
print([Link](arr))
print([Link](arr))

Reshaping an Array

arr = [Link]([1,2,3,4,5,6])
new_arr = [Link](2,3)
print(new_arr)

Simple Implementation Example


Find Average of Numbers Using NumPy

import numpyas np

n =int(input("Enter number of elements: "))


arr = [Link](1, n +1)

average = [Link](arr)
print("Array:", arr)
print("Average:", average)

Advantages of NumPy
High performance

Numpy 5
Easy syntax

Supports vectorized operations

Backbone for Pandas, SciPy, TensorFlow, etc.

Numpy 6

You might also like