numpy
  1. numpy-numpyravel

numpy.ravel() - ( Common NumPy Functions )

Heading h2

Syntax

numpy.ravel(a, order='C')

Example

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])
r_av = np.ravel(arr)

print(r_av)

Output

[1 2 3 4 5 6]

Explanation

numpy.ravel() is a function that returns a flattened 1D array from a 2D array or a multi-dimensional array. The function returns a 1D array after flattening or unraveling any dimension in the array. The order parameter specifies the way the elements from the input array are read.

Use

The numpy.ravel() method is used to return a 1D array by flattening the 2D or multi-dimensional array. The flattened array has the same data type as the original array and is created by reading all the elements of the original array in row-major order.

Important Points

  • numpy.ravel() returns a flattened 1D array from a 2D or multi-dimensional array
  • The flattened array has the same data type as the original array
  • The order parameter specifies the way the elements from the input array are read.

Summary

In conclusion, the numpy.ravel() function is a useful method to create a flattened 1D array from a 2D or multi-dimensional array. It is a versatile function that can help reshape data for further analysis or processing, and its order parameter allows for flexibility in how to read elements from the input array.

Published on: