0% found this document useful (0 votes)
14 views8 pages

NumPy Is A Powerful Python Library Used For Numerical Computing. Here Are S - 20250101 - 154624 - 0000

Uploaded by

rajukesani79
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)
14 views8 pages

NumPy Is A Powerful Python Library Used For Numerical Computing. Here Are S - 20250101 - 154624 - 0000

Uploaded by

rajukesani79
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/ 8

NumPy is a powerful Python

library used for numerical


computing. Here are some
essential skills and concepts
related to NumPy that you might
find useful:
1. Basics of NumPy

Importing NumPy:
python
Copy code
import numpy as np
Creating Arrays:
python
Copy code
arr = np.array([1, 2, 3]) # 1D array
arr_2d = np.array([[1, 2], [3, 4]]) #
2D array
2. Array Creation Methods

Zeros and Ones:


python
Copy code
np.zeros((2, 3)) # 2x3 array of
zeros
np.ones((3, 3)) # 3x3 array of
ones
Arange and Linspace:
python
Copy code
np.arange(0, 10, 2) # Array of
values [0, 2, 4, 6, 8]
np.linspace(0, 1, 5) # 5 evenly
spaced points between 0 and 1
Random Arrays:
python
Copy code
np.random.rand(3, 3) # Uniform
random values in a 3x3 array
np.random.randn(3, 3) # Normal
distribution
np.random.randint(0, 10, (2, 2))
# Integers between 0 and 10
3. Array Indexing and Slicing

Indexing:
python
Copy code
arr = np.array([10, 20, 30, 40])
print(arr[2]) # Output: 30
Slicing:
python
Copy code
arr = np.array([0, 1, 2, 3, 4])
print(arr[1:4]) # Output: [1, 2, 3]
Boolean Indexing:
python
Copy code
arr[arr > 2] # Returns elements
greater than 2
4. Array Operations

Elementwise Operations:
python
Copy code
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
print(a + b) # Output: [5, 7, 9]
Broadcasting:
python
Copy code
a = np.array([1, 2, 3])
print(a + 10) # Output: [11, 12,
13]
5. Shape Manipulation

Reshape:
python
Copy code
arr = np.array([1, 2, 3, 4, 5, 6])
arr = arr.reshape((2, 3)) #
Reshaped into 2 rows and 3
columns
Flatten:
python
Copy code
arr.flatten()
6. Aggregation and Statistics

Basic Statistics:
python
Copy code
arr = np.array([1, 2, 3, 4, 5])
arr.mean() # Mean
arr.sum() # Sum
arr.max() # Maximum
arr.min() # Minimum
arr.std() # Standard deviation
Axis-Based Aggregation:
python
Copy code
arr = np.array([[1, 2], [3, 4]])
arr.sum(axis=0) # Sum along
columns
arr.sum(axis=1) # Sum along
rows
7. Linear Algebra

Dot Product:
python
Copy code
np.dot(a, b)
Matrix Operations:
python
Copy code
np.linalg.inv(matrix) # Inverse
np.linalg.det(matrix) #
Determinant
8. Advanced Indexing

Fancy Indexing:
python
Copy code
arr = np.array([10, 20, 30, 40])
indices = [0, 2]
print(arr[indices]) # Output: [10,
30]
Masked Arrays:
python
Copy code
mask = arr > 20
print(arr[mask]) # Filter
elements greater than 20
9. File I/O

Saving and Loading:


python
Copy code
np.save('array.npy', arr)
arr = np.load('array.npy')
Saving as Text:
python
Copy code
n

You might also like