Q:

Write a NumPy program to create two arrays of size bigger and smaller than a given array

0

Write a NumPy program to create two arrays of size bigger and smaller than a given array.

All Answers

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

import numpy as np    
x = np.arange(16).reshape(4,4)
print("Original arrays:")
print(x)
print("\nArray with size 2x2 from the said array:")
new_array1 = np.resize(x,(2,2))
print(new_array1)
print("\nArray with size 6x6 from the said array:")
new_array2 = np.resize(x,(6,6))
print(new_array2)

Sample Output:

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

Array with size 2x2 from the said array:
[[0 1]
 [2 3]]

Array with size 6x6 from the said array:
[[ 0  1  2  3  4  5]
 [ 6  7  8  9 10 11]
 [12 13 14 15  0  1]
 [ 2  3  4  5  6  7]
 [ 8  9 10 11 12 13]
 [14 15  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