Untitled
unknown
plain_text
7 months ago
664 B
8
Indexable
import numpy as np
# Q2. Create a 5x5 NumPy array with random integers between 1 and 100.
arr = np.random.randint(1, 101, size=(5, 5))
print("Original Array:")
print(arr)
# A. Extract the elements from the second row and third column.
second_row = arr[1, :]
third_column = arr[:, 2]
print("\nSecond Row:")
print(second_row)
print("\nThird Column:")
print(third_column)
# B. Replace all the values in the second row with zeros.
arr[1, :] = 0
print("\nArray after replacing second row with zeros:")
print(arr)
# C. Extract a 3x3 sub-array starting from the third row and second column.
sub_array = arr[2:5, 1:4]
print("\n3x3 Sub-array:")
print(sub_array)
Editor is loading...
Leave a Comment