Write a NumPy program to create an 1-D array of 20 elements. Now create a new array of shape (5, 4) from the said array, then restores the reshaped array into a 1-D array
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
import numpy as np
array_nums = np.arange(0, 40, 2)
print("Original array:")
print(array_nums)
print("\nNew array of shape(5, 4):")
new_array = array_nums.reshape(5, 4)
print(new_array)
print("\nRestore the reshaped array into a 1-D array:")
print(new_array.flatten())
Sample Output:
Original array: [ 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38] New array of shape(5, 4): [[ 0 2 4 6] [ 8 10 12 14] [16 18 20 22] [24 26 28 30] [32 34 36 38]] Restore the reshaped array into a 1-D array: [ 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال