MADHAV INSTITUTE OF TECHNOLOGY & SCIENCE, GWALIOR
Deemed to be University
(Declared under Distinct Category by Ministry of Education, Government of India)
NAAC Accredited with A++ Grade
Department of Computer Science and Engineering
Course Title: Data Science Course Code: 150511/ 2290501
Assignment-3
Numpy
Instruction: Write Python code
Question 1:
Title: Slicing and Indexing
Description: Given a 4x4 NumPy array filled with consecutive integers starting from 1, extract
the 2x2 subarray from the bottom-right corner.
Question 2:
Title: Flattening Arrays
Description: Create a 3x3 NumPy array with random integers between 1 and 9. Flatten the array
into a 1D array.
Question 3:
Title: Cumulative Operations
Description: Generate a 1D NumPy array with 10 random integers between 1 and 20. Compute
the cumulative sum and cumulative product of the array.
Question 4:
Title: Linear Spacing
Description: Create a 1D NumPy array with 15 linearly spaced values between 10 and 50.
Reshape it into a 3x5 array.
Dr. Rohit Agrawal
MADHAV INSTITUTE OF TECHNOLOGY & SCIENCE, GWALIOR
Deemed to be University
(Declared under Distinct Category by Ministry of Education, Government of India)
NAAC Accredited with A++ Grade
Department of Computer Science and Engineering
Question 5:
Title: Sorting Arrays
Description: Generate a 1D NumPy array of 10 random integers. Sort the array in descending
order and find the index of the maximum value.
Question 6:
Title: Inverse and Determinant
Description: Create a 3x3 NumPy array with random integers. Calculate the determinant and
inverse of the array, ensuring it is invertible.
Question 7:
Title: Eigenvalues and Eigenvectors
Description: Create a 2x2 matrix with specific integer values. Compute its eigenvalues and
eigenvectors.
Question 8:
Title: Logical Operations
Description: Given a 1D NumPy array of 10 random integers, find the indices where the array
elements are even and greater than 5.
Question 9:
Title: Array Concatenation
Description: Create three 1D NumPy arrays with 5 random integers each. Concatenate them into
a single 1D array.
Question 10:
Title: Fourier Transform
Description: Create a 1D NumPy array of 100 evenly spaced values between 0 and 2π. Compute
the Fast Fourier Transform (FFT) of the array.
Dr. Rohit Agrawal
MADHAV INSTITUTE OF TECHNOLOGY & SCIENCE, GWALIOR
Deemed to be University
(Declared under Distinct Category by Ministry of Education, Government of India)
NAAC Accredited with A++ Grade
Department of Computer Science and Engineering
Question 11: Title: Scalar Broadcasting
Description: Create a 2D NumPy array with shape (4, 3) filled with random integers between 1
and 10. Add a scalar value of 5 to each element using broadcasting.
Question 12: Title: Vector Broadcasting
Description: Given a 3x3 matrix and a 1D array of size 3, use broadcasting to add the 1D array to
each row of the matrix.
Question 13: Title: Broadcasting with Different Shapes
Description: Create a 2D NumPy array with shape (4, 5) filled with random integers between 0
and 10. Create a 1D array with shape (5,). Subtract the 1D array from each row of the 2D array
using broadcasting.
Question 14: Title: Column-wise Broadcasting
Description: Generate a 2D NumPy array with shape (5, 4) and a 1D array of shape (5,). Use
broadcasting to multiply each column of the 2D array by the corresponding element in the 1D
array.
Question 15: Title: Broadcasting with Scalar Multiplication
Description: Create a 1D array with shape (10,). Reshape it into a 2D array of shape (10, 1) and
multiply it with a scalar value to demonstrate broadcasting.
Question 16: Title: Broadcasting in Element-wise Division
Description: Given a 3x4 matrix of integers, divide each element by a 1D array of length 4 using
broadcasting, and print the resulting matrix.
Question 17: Title: Broadcasting with 3D Arrays
Description: Create a 3D NumPy array with shape (2, 3, 4) and a 2D array with shape (3, 4). Add
the 2D array to each "slice" of the 3D array using broadcasting.
Dr. Rohit Agrawal
MADHAV INSTITUTE OF TECHNOLOGY & SCIENCE, GWALIOR
Deemed to be University
(Declared under Distinct Category by Ministry of Education, Government of India)
NAAC Accredited with A++ Grade
Department of Computer Science and Engineering
Question 18: Title: Broadcasting in Arithmetic Operations
Description: Create two 1D arrays of different sizes, one with 4 elements and another with 8
elements. Reshape the smaller array and use broadcasting to add them together.
Question 19: Title: Broadcasting and Boolean Masking
Description: Create a 3x3 matrix of random integers between 1 and 10. Use broadcasting to
compare each element to the mean of the matrix and create a boolean mask where elements
greater than the mean are True.
Question 20: Title: Broadcasting with Different Dimensions
Description: Create a 2x5 matrix and a 1x5 row vector. Subtract the row vector from each row of
the matrix using broadcasting, and then add a column vector with shape (2, 1) to the result.
Dr. Rohit Agrawal