Python’s ravel()
function is used to return a contiguous array. This function returns a 1D
array that contains the input elements.
The syntax for this function is as follows:
numpy.ravel(a, order='C')
The ravel()
function takes the following parameter values:
a
: This represents the input array.order
: This represents the type of order for the memory layout. This parameter value is optional. It can take a "C"
, "F"
, "A"
, or "K'
order.The ravel()
function returns an array of the same subtype and shape as that of the input array a
that is passed to it.
import numpy as np# creating an arraymyarray1 = np.array([[1, 2, 3], [4, 5, 6]])# calling the ravel() functionmyarray2 = np.ravel(myarray1, order = "K")print(myarray2)# checking the size of the imput and output arraysprint(myarray1.size)print(myarray2.size)
numpy
module.2D
array called myarray1
, using the array()
function.myarray1
, using an order style K
. We assign the result to another variable called myarray2
.myarray2
.array.size()
function.