Python NumPy ravel function example Showing ordering manipulation

66

# Welcome to softhunt.net
# Python Program illustrating
# numpy.ravel() method

import numpy as np

array = np.arange(15).reshape(5, 3)
print("Original array : \n", array)

# Output comes like [ 0 1 2 ..., 12 13 14]
# as it is a long output, so it is the way of
# showing output in Python

# About :
print("\nAbout numpy.ravel() : ", array.ravel)

print("\nnumpy.ravel() : ", array.ravel())

# Maintaining both 'A' and 'F' order
print("\nMaintains A Order : ", array.ravel(order = 'A'))

# K-order preserving the ordering
# 'K' means that is neither 'A' nor 'F'
array2 = np.arange(12).reshape(2,3,2).swapaxes(1,2)
print("\narray2 \n", array2)
print("\nMaintains A Order : ", array2.ravel(order = 'K'))

Comments

Submit
0 Comments