Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

reshape

# Python Program illustrating
# numpy.reshape() method
 
import numpy as geek
 
# array = geek.arrange(8)
# The 'numpy' module has no attribute 'arrange'
array1 = geek.arange(8)
print("Original array : 
", array1)
 
# shape array with 2 rows and 4 columns
array2 = geek.arange(8).reshape(-1, 1)
print("
array reshaped with 2 rows and 4 columns : 
",
      array2)
 
# shape array with 4 rows and 2 columns
array3 = geek.arange(8).reshape(4, 2)
print("
array reshaped with 2 rows and 4 columns : 
",
      array3)
 
# Constructs 3D array
array4 = geek.arange(8).reshape(2, 2, 2)
print("
Original array reshaped to 3D : 
",
      array4)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #reshape
ADD COMMENT
Topic
Name
6+3 =