Q. Create a 2-D array called myarray4 using arange() having 14 rows and 3 columns with start value = -1, step size 0.25 having. Split this array row wise into 3 equal parts and print the result.
Answer :
import numpy as np
# Create a 2-D array using arange
myarray4 = np.arange(-1, -1 + 14 * 3 * 0.25, 0.25).reshape(14, 3)
print(myarray4)
print()
# Split the array row-wise into 3 equal parts
result = np.array_split(myarray4, 3)
# Print the result
for i, part in enumerate(result):
print(f"Part {i + 1}:\n{part}\n")
print()
Explanation:
In above code:
1. np.arange(-1, -1 + 14 * 3 * 0.25, 0.25) generates a 1-D array starting from -1 with a step size of 0.25 and a total of 14 * 3 elements.
2. reshape(14, 3) reshapes the 1-D array into a 2-D array with 14 rows and 3 columns.
3. np.array_split(myarray4, 3) splits the array row-wise into 3 equal parts.
4. The result is then printed, showing each part separately.
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )