Numpy Task
Part 1: Creating and Reshaping Arrays
1. Create Arrays:
o Create two NumPy arrays:
▪ A 1D array of 10 equally spaced values between 0 and 50.
▪ A 2D array of shape (3x3) containing random integers
between 5 and 20.
2. Array Dimensions:
o Print the dimensions of both arrays.
o Print the shape of both arrays.
3. Reshaping:
o Reshape the 1D array into a 2D array with shape (2x5).
o Print the reshaped array.
o Flatten the reshaped array back to 1D and print it.
Part 2: Indexing and Slicing
4. Indexing:
o For the 2D array created in Part 1, print the element present at the
2nd row and 3rd column.
o Extract the first two rows and the last two columns of the array.
5. Slicing:
o Slice the first four elements from the flattened 1D array.
o Reverse the elements of the 1D array using slicing.
Part 3: Array Operations
6. Array Arithmetic:
o Create another 1D array of 10 integers between 1 and 10.
o Perform the following element-wise operations between the 1D
arrays created in Part 1 and Part 3:
▪ Addition
▪ Multiplication
▪ Subtract a constant value (e.g., 5) from the array.
Part 4: Random Number Generation and Copying
7. Random Numbers:
o Create a 1D array of 5 random values between 0 and 1.
o Create another 1D array of 5 random values between -1 and 1.
8. Copy vs View:
o Create a copy of the original 2D array from Part 1.
o Modify one element in the copy and show that it doesn’t affect the
original array.
o Create a view of the original 2D array and modify one element.
Show that it does affect the original array.
Part 5: Bonus
9. Challenge Task:
o Write a program that asks the user to input a number (n), and then
generates an n x n array of random integers between 1 and 100.
o Find the sum of all the elements in the array and print the result.