Q1) Implementation of Python Basic Libraries such as Statistics, Math,
Numpy and Scipy
a) Usage of methods such as floor(), ceil(), sqrt(), isqrt(), gcd() etc.
b) Usage of attributes of array such as ndim, shape, size, methods
such as sum(), mean(), sort(), sin() etc.
c) Usage of methods such as det(), eig() etc.
d) Consider a list datatype(1D) then reshape it into2D, 3D matrix
using numpy
e) generate matrices and perform operations on matrices using
NumPy in Python.
f) Find the determinant of a matrix using scipy
g) Find eigen value and eigen vector of a matrix using scipy
a) Usage of methods such as floor(), ceil(), sqrt(), isqrt(), gcd() etc.
These methods are provided by the built-in math module in Python.
floor(x) → Largest int ≤ x
ceil(x) → Smallest int ≥ x
sqrt(x) → Square root (float)
isqrt(x) → Integer square root
gcd(x, y) → Greatest Common Divisor
Output:
b) Usage of attributes of array such as ndim, shape, size, methods such as sum(), mean(), sort(),
sin() etc.
ndim: Number of dimensions in the array.
shape: Tuple indicating rows and columns.
size: Total number of elements.
dtype: Data type of array elements.
sum(): Adds all elements.
mean(): Returns average value.
sort(): Sorts elements.
sin(): Computes sine (useful in scientific applications).
c) Usage of methods such as det(), eig() etc.
To perform determinant, eigenvalues, and eigenvectors, we use:
numpy.linalg.det() for determinant
numpy.linalg.eig() for eigenvalues and eigenvectors
d) Consider a list datatype(1D) then reshape it into2D, 3D matrix using numpy
reshape(rows, columns) reshapes a flat array into 2D.
reshape(blocks, rows, columns) reshapes into 3D.
Total elements must remain same:
2 × 4 = 8, 2 × 2 × 2 = 8 → valid reshapes.
e) generate matrices and perform operations on matrices using NumPy in Python.
Generating Matrices:
Function Description Example
np.array() Create matrix from list np.array([[1,2],[3,4]])
np.zeros() Matrix of all zeros np.zeros((2, 3))
np.ones() Matrix of all ones np.ones((3, 2))
np.eye() Identity matrix np.eye(3)
np.random.rand() Matrix with random values np.random.rand(2, 3)
Operation Function Example
Addition + or np.add() A+B
Subtraction - or np.subtract() A-B
Multiplication * (element-wise) or np.dot() (matrix mult) np.dot(A, B)
Transpose A.T or np.transpose(A) A.T
Inverse np.linalg.inv(A) Only if matrix is square and invertible
Output:
f) Find the determinant of a matrix using scipy
scipy.linalg.det()
This is used from the scipy.linalg module to compute the determinant of a square matrix.
scipy.linalg.det() → computes determinant of a matrix
Works with any square NumPy array
More precise and optimized than numpy.linalg.det() in some large matrix cases
Output:
g) Find eigen value and eigen vector of a matrix using scipy
Use scipy.linalg.eig(matrix) to compute:
o Eigenvalues
o Eigenvectors
Eigenvectors are returned column-wise
Output may include complex numbers
Output:
What is NumPy?
NumPy stands for Numerical Python.
It is a powerful Python library used for numerical and scientific computing, especially when
working with arrays and matrices.
Feature Description
Multidimensional arrays Powerful N-dimensional array object (ndarray)
Mathematical functions Fast element-wise math operations
Broadcasting Apply operations between arrays of different shapes
Linear algebra tools Matrix multiplication, inverse, transpose, etc.
Random number generation Create random arrays for simulations
Performance Much faster than Python lists (written in C)
What is SciPy?
SciPy stands for Scientific Python.
It is an open-source scientific computing library built on top of NumPy, designed to perform
advanced mathematical, scientific, and engineering computations.
SciPy Provides:
Linear algebra operations
Optimization algorithms
Signal and image processing
Numerical integration
Interpolation
Fourier transforms
Statistics and probability functions
SciPy is Built On:
NumPy – for array handling
matplotlib – for plotting (often used alongside SciPy)
Python standard libraries