numpy.reshape



This function gives a new shape to an array without changing the data. It accepts the following parameters −

numpy.reshape(arr, newshape, order')

Where,

Sr.No. Parameter & Description
1

arr

Array to be reshaped

2

newshape

int or tuple of int. New shape should be compatible to the original shape

3

order

'C' for C style, 'F' for Fortran style, 'A' means Fortran like order if an array is stored in Fortran-like contiguous memory, C style otherwise

Example

import numpy as np
a = np.arange(8)
print 'The original array:'
print a
print '\n'

b = a.reshape(4,2)
print 'The modified array:'
print b

Its output would be as follows −

The original array:
[0 1 2 3 4 5 6 7]

The modified array:
[[0 1]
 [2 3]
 [4 5]
 [6 7]]
numpy_array_manipulation.htm
Advertisements