Q:

Write a NumPy program to create a new shape to an array without changing its data

0

Write a NumPy program to create a new shape to an array without changing its data

All Answers

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

import numpy as np
x = np.array([1, 2, 3, 4, 5, 6])
y = np.reshape(x,(3,2))
print("Reshape 3x2:")
print(y)
z = np.reshape(x,(2,3))
print("Reshape 2x3:")
print(z)

Sample Output:

Reshape 3x2:                                                           
[[1 2]                                                                 
 [3 4]                                                                 
 [5 6]]                                                                
Reshape 2x3:                                                           
[[1 2 3]                                                               
 [4 5 6]] 

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