Lab Exercise Questions (Q1 - Q30)
1. Create an integer array with values from 1 to 10. Add the value 20, remove the value 5, print all elements,
sort it, reshape into 2 rows, and slice the first row.
2. Create a float array with 6 values. Append 3 new values, delete the last one, print each value with its
index, sort the array, reshape it to 3x3, and display the center element.
3. Generate a 1D array of 12 random integers between 10 and 100. Print its data type, add 55, remove index
3, sort the array, reshape it to 3x4, and slice all even-indexed columns.
4. Create a 3x3 array of integers. Add a new row, remove the second column, print the updated array, sort
each row, reshape to 1D, and slice the last 4 elements.
5. Create an array of 15 linearly spaced values between 0 and 10. Add 100 at the end, delete the third
element, print all values greater than 5, sort, reshape into 5x3, and extract the last row.
6. Create a 1D array from a list of 8 elements with type float. Add two elements, remove one by value, print
the array with indices, sort it, reshape to 2x5, and print the second column.
7. Generate a boolean array of 10 elements. Add a True value, remove a False, print all items, sort, reshape
to 2x5, and slice the first 3 columns.
8. Create an integer array with repeating elements. Add a new integer, remove duplicates using indexing,
print, sort, reshape to 2D, and slice a subarray.
9. Create a 2D integer array, convert to float, add a column, remove a row, print it, sort by column, reshape to
1D, and slice every second value.
10. Create a 1D complex number array. Add another complex number, delete the first item, print real parts,
sort by magnitude, reshape to 2x2, and print both diagonals.
11. Create a NumPy array with dtype string. Add a new element, remove one, print all, sort alphabetically,
reshape to 3x2, and slice the first two rows.
12. Create a 4x4 identity matrix, add 2 to all elements, delete one row, print it, sort it row-wise, reshape to
8x2, and slice the last 4 values.
13. Generate a random integer array of shape 3x3. Add a new column with zeros, remove the last column,
print the array, sort all rows, reshape to 1D, and slice every third element.
14. Create an array of type float with 10 values. Add a new float, delete one element using index, print the
min and max, sort, reshape to 2x5, and slice values < 5.
, NumPy Lab Exercises (Integrated Tasks)
15. Create a list of 10 numbers and convert it to a NumPy array. Add 999, remove index 4, print each item,
sort, reshape to 5x2, and slice all rows where first column > 500.
16. Create a 3D array of shape (2,2,3). Add a new layer using np.append, remove one row, print the shape,
flatten it, sort, and slice elements from index 5 to 10.
17. Create a NumPy array of 25 values using arange(). Add 25, remove all even numbers using boolean
indexing, print, sort descending, reshape to 5x2, and print the transpose.
18. Create a 1D array of 12 elements. Add 2 elements at the beginning, remove the middle element, print
using a loop, sort, reshape to 3x5, and slice the corner values.
19. Create an array with np.linspace from 0 to 1 in 11 steps. Add 0.5, remove the first value, print, sort,
reshape to 3x4, and print values in the last column.
20. Create a 6x6 array of random integers. Add 1 to each element, remove the first row, print it, sort columns,
reshape to 3D array, and slice the top-left 2x2 submatrix.
21. Create a 10-element float array with values between 1 and 100. Add a new max value, remove the
smallest, print, sort, reshape to 2x5, and slice the second row.
22. Create a 1D array of type int32. Add 5 elements, delete 2 elements using slicing, print in reverse, sort,
reshape to 3x3, and extract the diagonal.
23. Create a 4x4 array filled with 7. Add a new row with value 1, remove the third column, print the result,
sort, reshape to 2x8, and slice the last 4 values.
24. Create an array using a tuple and specify dtype. Add a new value, remove by slicing, print all, sort,
reshape to 6x1, and print all rows > 20.
25. Create a structured array with int and float fields. Add a new record, delete one, print all, sort by float field,
reshape fields as needed, and slice values from a field.
26. Create a 3x3 matrix using nested lists. Add a new row, delete a column, print updated matrix, sort rows,
reshape to 1D, and slice the center 3 values.
27. Create an array of 8 random values. Add 3 more values, remove 2 smallest, print final array, sort,
reshape to 2x5, and slice last two rows.
28. Create a 2x5 integer array. Add one column with constant value, remove a row, print each row, sort each
row, reshape to 5x2, and slice second column.
29. Create an array with mixed positive and negative numbers. Add a positive number, remove negatives,