21 August 2020
Code
# Import library
import numpy as np
# Create an array
x = np.array([[1,2,3,4],
[10,20,30,40],
[100,200,300,400]])
# Reshape
y = x.reshape(6,2)
# Output
print('Original array:\n', x, '\n', 'Shape:',x.shape,'\n')
print('Reshaped array:\n', y, '\n', 'Shape:',y.shape,'\n')
Original array:
[[ 1 2 3 4]
[ 10 20 30 40]
[100 200 300 400]]
Shape: (3, 4)
Reshaped array:
[[ 1 2]
[ 3 4]
[ 10 20]
[ 30 40]
[100 200]
[300 400]]
Shape: (6, 2)
Any errors in code above?
Please send a message.