numpy.ndarray.flatten() in Python

The Python numpy.ndarray.flatten() function returns the copy of array that’s collapsed into a one-dimensional array.

Basic Syntax

Following is the basic syntax for numpy.argmin() function in Python:

numpy.flatten(order=’C’)

And the parameters are:

ParameterDescription
order[OPTIONAL], values ca be {‘C’, ‘F’, ‘A’, ‘K’}. Where C means flatten row-major, F means flatten column-major, A means flatten in column-major order if a is Fortran contiguous in memory else row-major order, K means to flatten in order elements occur in memory.

Return Value

This function returns a copy of array collapsed into a one-dimensional array.

Example’s

Following are the examples for numpy.flatten() function:

Example 1

The output for the above program is as given below:

The input array:
[[1, 2], [3, 4]]
The flattened array: [1, 2, 3, 4]

Example 2

The output for the above program is as given below:

The input array:
[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]]
The flattened array: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

LEAVE A REPLY

Please enter your comment!
Please enter your name here