Q:

Write a NumPy program to create a 4x4 array with random values, now create a new array from the said array swapping first and last rows

0

Write a NumPy program to create a 4x4 array with random values, now create a new array from the said array swapping first and last rows

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np 
nums = np.arange(16, dtype='int').reshape(-1, 4)
print("Original array:")
print(nums)
print("\nNew array after swapping first and last rows of the said array:")
new_nums = nums[::-1]
print(new_nums)

Sample Output:

Original array:
[[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 15]]

New array after swapping first and last rows of the said array:
[[12 13 14 15]
 [ 8  9 10 11]
 [ 4  5  6  7]
 [ 0  1  2  3]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now