# Return a 1D version of self as a view with elements in the order they occur in memory in Numpy

To return a 1D version of self as a view, use the ma.MaskedArray.ravel() method in Numpy. The order is set using the "order" parameter, to read the elements using the index order. The ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative.

The elements of a are read using this index order. ‘C’ means to index the elements in C-like order, with the last axis index changing fastest, back to the first axis index changing slowest. ‘F’ means to index the elements in Fortran-like index order, with the first index changing fastest, and the last index changing slowest.

The ‘C’ and ‘F’ options take no account of the memory layout of the underlying array, and only refer to the order of axis indexing. ‘A’ means to read the elements in Fortran-like index order if m is Fortran contiguous in memory, C-like order otherwise. ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative. By default, ‘C’ index order is used.

## Steps

At first, import the required library −

import numpy as np
import numpy.ma as ma

Create an array with int elements using the numpy.array() method −

arr = np.array([[49, 85, 45], [67, 33, 59]])
print("Array...", arr)
print("Array type...", arr.dtype)

Get the dimensions of the Array −

print("Array Dimensions...",arr.ndim)


Create a masked array and mask some of them as invalid −

maskArr = ma.masked_array(arr, mask =[[0, 0, 1], [ 0, 1, 0]])
print("Our Masked Array type...", maskArr.dtype)

Get the dimensions of the Masked Array −

print("Our Masked Array Dimensions...",maskArr.ndim)


Get the shape of the Masked Array −

print("Our Masked Array Shape...",maskArr.shape)

Get the number of elements of the Masked Array −

print("Elements in the Masked Array...",maskArr.size)


Return a 1D version of self as a view, use the ma.MaskedArray.ravel() method in Numpy. The order is set using the "order" parameter, to read the elements using the index order −

print("Result...",maskArr.ravel(order='K'))

## Example

# Python ma.MaskedArray - Returns a 1D version of self as a view with elements in the order they occur in memory

import numpy as np
import numpy.ma as ma

# Create an array with int elements using the numpy.array() method
arr = np.array([[78, 85, 51], [56, 33, 97]])
print("Array...", arr)
print("Array type...", arr.dtype)

# Get the dimensions of the Array
print("Array Dimensions...",arr.ndim)

# Create a masked array and mask some of them as invalid

# Get the dimensions of the Masked Array

# Get the shape of the Masked Array

# Get the number of elements of the Masked Array

# To return a 1D version of self as a view, use the ma.MaskedArray.ravel() method in Numpy
# The order is set using the "order" parameter, to read the elements using the index order.
# The ‘K’ means to read the elements in the order they occur in memory, except for reversing the data when strides are negative
print("Result...",maskArr.ravel(order='K'))

## Output

Array...
[[78 85 51]
[56 33 97]]

Array type...
int32

Array Dimensions...
2

[[78 -- 51]
[56 33 97]]

int32

[78 -- 51 56 33 97]