python library functions:Numpy functions.docx

NandhiniReddy24 0 views 7 slides Oct 06, 2025
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

python libraries


Slide Content

NumPy Functions in Python3
1. Array Creation
np.array() – Create an array from list/tuple.
np.zeros(shape) – Create array filled with 0.
np.ones(shape) – Create array filled with 1.
np.empty(shape) – Create array without initializing entries.
np.arange(start, stop, step) – Create range array.
np.linspace(start, stop, num) – Create evenly spaced numbers.
np.logspace(start, stop, num) – Logarithmically spaced values.
np.eye(n) – Identity matrix.
np.identity(n) – Identity array.
np.random.rand(), np.random.randn() – Random arrays.

---
2. Array Inspection
np.shape(arr) – Dimensions of array.
np.size(arr) – Total number of elements.
np.ndim(arr) – Number of dimensions.
np.dtype(arr) – Data type of array elements.
np.itemsize – Size of one array element (bytes).
---
3. Array Reshaping & Manipulation
np.reshape(arr, new_shape)
np.ravel(arr) – Flatten into 1D.
np.flatten() – Convert to 1D (copy).

np.transpose(arr) or arr.T
np.hstack(), np.vstack()
np.concatenate((a, b), axis=...)
np.split(arr, sections)
---
4. Mathematical Operations
Element-wise:
np.add(a, b), np.subtract(a, b)
np.multiply(a, b), np.divide(a, b)
np.power(a, b)
np.mod(a, b)
Trigonometric:

np.sin(x), np.cos(x), np.tan(x)
np.arcsin(x), np.arccos(x), np.arctan(x)
np.deg2rad(x), np.rad2deg(x)
Exponential & Logarithmic:
np.exp(x), np.log(x), np.log10(x)
np.sqrt(x)
Rounding:
np.round(x), np.floor(x), np.ceil(x)
---
5. Aggregate Functions (Statistics)

np.min(arr), np.max(arr)
np.argmin(arr), np.argmax(arr)
np.sum(arr)
np.mean(arr)
np.median(arr)
np.std(arr) – Standard deviation.
np.var(arr) – Variance.
np.percentile(arr, q)
np.corrcoef(x, y)
np.cov(x, y)
---
6. Linear Algebra (via numpy.linalg)

np.dot(a, b) – Dot product.
np.matmul(a, b) – Matrix multiplication.
np.inner(a, b) – Inner product.
np.outer(a, b) – Outer product.
np.cross(a, b) – Cross product.
np.linalg.inv(A) – Inverse of a matrix.
np.linalg.det(A) – Determinant.
np.linalg.eig(A) – Eigenvalues and eigenvectors.
np.linalg.solve(A, b) – Solve linear system.
np.linalg.norm(A) – Matrix/vector norm.
---
7. Random Numbers (np.random)

np.random.rand(d0, d1, ...) – Uniform [0,1).
np.random.randn(d0, d1, ...) – Standard normal distribution.
np.random.randint(low, high, size) – Random integers.
np.random.choice(seq) – Random choice from sequence.
np.random.shuffle(arr) – Shuffle array (in-place).
np.random.permutation(arr) – Permuted array copy.
---
8. Input/Output
np.loadtxt(filename) – Load from text file.
np.savetxt(filename, arr) – Save to text file.
np.save(filename, arr) – Save in .npy format.
np.load(filename) – Load .npy file.
Tags