numpy.ravel() in Python Last Updated : 23 Dec, 2024 Comments Improve Suggest changes Like Article Like Report The numpy.ravel() functions returns contiguous flattened array(1D array with all the input-array elements and with the same type as it). A copy is made only if needed. Syntax : numpy.ravel(array, order = 'C')Parameters : array : [array_like]Input array. order : [C-contiguous, F-contiguous, A-contiguous; optional] C-contiguous order in memory(last index varies the fastest) C order means that operating row-rise on the array will be slightly quicker FORTRAN-contiguous order in memory (first index varies the fastest). F order means that column-wise operations will be faster. ‘A’ means to read / write the elements in Fortran-like index order if, array is Fortran contiguous in memory, C-like order otherwiseReturn : Flattened array having same type as the Input array and and order as per choice. Code 1 : Shows that array.ravel is equivalent to reshape(-1, order=order) Python # Python Program illustrating # numpy.ravel() method import numpy as geek array = geek.arange(15).reshape(3, 5) 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 print("\nravel() : ", array.ravel()) # This shows array.ravel is equivalent to reshape(-1, order=order). print("\nnumpy.ravel() == numpy.reshape(-1)") print("Reshaping array : ", array.reshape(-1)) Output : Original array : [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14]]ravel() : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]numpy.ravel() == numpy.reshape(-1)Reshaping array : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]Code 2 :Showing ordering manipulation Python # Python Program illustrating # numpy.ravel() method import numpy as geek array = geek.arange(15).reshape(3, 5) 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 = geek.arrange(12).reshape(2,3,2).swapaxes(1,2) print("\narray2 \n", array2) print("\nMaintains A Order : ", array2.ravel(order = 'K')) Output : Original array : [[ 0 1 2 3 4] [ 5 6 7 8 9] [10 11 12 13 14]]About numpy.ravel() : <built-in method ravel of numpy.ndarray object at 0x000001F10F3F8930>numpy.ravel() : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]Maintains A Order : [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14]array2 [[[ 0 2 4] [ 1 3 5]] [[ 6 8 10] [ 7 9 11]]]Maintains A Order : [ 0 1 2 3 4 5 6 7 8 9 10 11]Note : These codes won’t run on online IDE's. Please run them on your systems to explore the working. Comment More infoAdvertise with us Next Article numpy.ravel() in Python M Mohit Gupta_OMG Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads numpy.rint() in Python The numpy.rint() is a mathematical function that rounds elements of the array to the nearest integer. Syntax : numpy.rint(x[, out]) = ufunc ârintâ) Parameters : array : [array_like] Input array. Return : An array with all array elements being rounded off, having same type and shape as input. Code #1 2 min read numpy.std() in Python numpy.std() is a function provided by the NumPy library that calculates the standard deviation of an array or a set of values. Standard deviation is a measure of the amount of variation or dispersion of a set of values.\text{Standard Deviation} = \sqrt{\text{mean} \left( (x - x.\text{mean}())^2 \rig 3 min read numpy.random.weibull() in Python With the help of numpy.random.weibull() method, we can get the random samples from weibull distribution and return the random samples as numpy array by using this method. Weibull Distribution Syntax : numpy.random.weibull(a, size=None) Return : Return the random samples as numpy array. Example #1 : 1 min read numpy.random.rand() in Python This article provides an in-depth exploration of the `numpy.random.rand()` function in Python. It covers the function's syntax, and definition, and includes illustrative examples with detailed explanations for better understanding. numpy.random.rand() Function Syntax The numpy.random.rand() function 3 min read numpy.random.shuffle() in python With the help of numpy.random.shuffle() method, we can get the random positioning of different integer values in the numpy array or we can say that all the values in an array will be shuffled randomly. Syntax : numpy.random.shuffle(x) Return : Return the reshuffled numpy array. Example #1 : In this 1 min read numpy.random.zipf() in Python With the help of numpy.random.zipf() method, we can get the random samples from zipf distribution and return the random samples as numpy array by using this method. Zipf distribution Syntax : numpy.random.zipf(a, size=None) Return : Return the random samples as numpy array. Example #1 : In this exam 1 min read Numpy recarray.ravel() function | Python In numpy, arrays may have a data-types containing fields, analogous to columns in a spreadsheet. An example is [(a, int), (b, float)], where each entry in the array is a pair of (int, float). Normally, these attributes are accessed using dictionary lookups such as arr['a'] and arr['b']. Record array 3 min read Python NumPy Numpy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python.Besides its obvious scientific uses, Numpy can also be used as an efficient m 6 min read numpy.load() in Python numpy.load() function return the input array from a disk file with npy extension(.npy). Syntax : numpy.load(file, mmap_mode=None, allow_pickle=True, fix_imports=True, encoding='ASCII') Parameters: file : : file-like object, string, or pathlib.Path.The file to read. File-like objects must support the 2 min read numpy.ceil() in Python The numpy.ceil() is a mathematical function that returns the ceil of the elements of array. The ceil of the scalar x is the smallest integer i, such that i >= x Syntax : numpy.ceil(x[, out]) = ufunc âceilâ) Parameters : a : [array_like] Input array Return : The ceil of each element with float dat 2 min read Like