0% found this document useful (0 votes)
3 views

Numpy

NumPy is a fundamental library for scientific computing in Python, providing high-performance multidimensional arrays and tools for their manipulation. It offers various methods for creating, saving, loading, and inspecting arrays, as well as performing arithmetic and mathematical operations. Additionally, NumPy supports multiple data types and efficient memory usage, making it essential for handling large datasets.

Uploaded by

rohitsul1112003
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)
3 views

Numpy

NumPy is a fundamental library for scientific computing in Python, providing high-performance multidimensional arrays and tools for their manipulation. It offers various methods for creating, saving, loading, and inspecting arrays, as well as performing arithmetic and mathematical operations. Additionally, NumPy supports multiple data types and efficient memory usage, making it essential for handling large datasets.

Uploaded by

rohitsul1112003
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
You are on page 1/ 18

Python

Library

NUMPY
PRESENTATION :

Scientific Computing
PRESENTATION :
NumPy is the essential library for scientific
computing in Python. It provides a high-
performance multidimensional array object
and tools for working with these arrays.
CREATING ARRAYS :
NumPy provides a variety of ways to create arrays. These
methods allow you to generate arrays of different shapes
and values, whether you're looking for zeros, ones, random
numbers, or evenly spaced values. Let’s explore some of
the most common ways to create arrays in NumPy!
CREATING ARRAYS :
SAVING AND
LOADING DATA
NumPy provides several functions for saving and loading arrays
to and from disk, allowing you to easily store and retrieve large
datasets. Let's take a look at the most commonly used methods
for saving and loading NumPy arrays.

Saving Arrays to Disk


Loading Arrays from Disk

Saving and Loading Text Files


Handling Missing Data

Note :

np.save() and np.load() handle binary files (.npy).

np.savetxt() and np.loadtxt() are for text files (.txt).

np.genfromtxt() is particularly useful when dealing

with missing data in text files.


INSPECTING YOUR
ARRAY
NumPy arrays come with useful attributes and methods that
allow you to inspect their properties, such as their shape, data
type, and size.

Common Array Inspections :


Explanation :

shape: Returns a tuple representing the dimensions of the array.

len(): Returns the size of the first dimension.

ndim: Returns the number of dimensions (axes) of the array.

size: Returns the total number of elements in the array.

dtype: Returns the data type of the array elements (e.g., int64, float32).

astype(): Allows you to cast an array to a different data type (e.g.,

converting float to int).

These methods and attributes are helpful for quickly gathering


information about your arrays and ensuring you're working with
the right data types and dimensions!
DATA TYPES IN
NUMPY
NumPy provides a wide range of data types for storing different
kinds of data. Here's a look at some of the most commonly used
data types in NumPy arrays.

Common Data Type :


Explanation :

np.int64: 64-bit signed integer type, typically used for large integer

values.

np.float32: 32-bit floating-point type, commonly used for floating-

point operations requiring less memory.

np.complex128: Represents complex numbers using 128-bit floating-

point numbers.

np.bool_: Boolean type to store True or False values.

np.object: A generic type for storing Python objects.

np.string_: Fixed-length ASCII string type.

np.unicode_: Fixed-length Unicode string type, useful for handling

international characters.

These data types allow NumPy to efficiently store and


manipulate different kinds of data in arrays. Choosing the
appropriate data type for your array can have a significant
impact on performance and memory usage.
ARRAY
MATHEMATICS
NumPy allows you to perform various arithmetic operations
directly on arrays, including addition, subtraction,
multiplication, division, and more. These operations are
element-wise, meaning they operate on corresponding
elements of arrays.

Basic Arithmetic Operations :


Other Mathematical Functions :

Dot Product :
Comparison Operations :

Aggregate Functions :
COPYING ARRAYS
In NumPy, you can either create a view of an array or make an
independent copy. A view does not create a new array in
memory; instead, it provides a reference to the original array. A
copy creates a new array with its own data.

Creating a View of an Array :

Creating a Copy of an Array :

Creating a Deep Copy of an Array :


KEY CONCEPTS IN
NUMPY
1. Creating Arrays:
Methods to create arrays:
np.array(), np.zeros(), np.ones(), np.arange(), np.linspace()
Special arrays:
np.eye() (identity matrix), np.full(), np.random.random()
2. Inspecting Arrays:
Key attributes:
shape, size, ndim
Data type and conversion:
dtype, astype()
3. Array Operations:
Element-wise arithmetic:
+, -, *, /
Mathematical functions:
np.exp(), np.sqrt(), np.sin(), np.cos(), np.log()
Dot product:
.dot()
KEY CONCEPTS IN
NUMPY
4. Comparison Operations:
Element-wise comparisons with operators:
==, <, >, etc.
5. Aggregate Functions:
Key functions for summary statistics:
sum(), min(), max(), mean(), std(), median(), cumsum()
6. Saving and Loading Data:
Functions for reading and writing arrays:
np.save(), np.load(), np.savetxt(), np.loadtxt()
7. Copying Arrays:
View vs Copy:
a.view(), np.copy(), a.copy()
Find this
useful ?
Save It

Follow Me

Repost it

Haitam Marzouki

You might also like