# Return a 1D version of self as a view in Numpy

NumpyServer Side ProgrammingProgramming

To return a 1D version of self as a view in Python, use the ma.MaskedArray.ravel() method in Numpy.

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("
print("
", maskArr.dtype)

Get the dimensions of the Masked Array −

print("


Get the shape of the Masked Array −

print("
",maskArr.shape)

Get the number of elements of the Masked Array −

print("


Return a 1D version of self as a view, use the ma.MaskedArray.ravel() method in Numpy −

print("
Result...
",maskArr.ravel())

## Example

# Python ma.MaskedArray - Returns a 1D version of self as a view

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
print("
print("

# Get the dimensions of the Masked Array
print("

# Get the shape of the Masked Array
print("

# Get the number of elements of the Masked Array
print("

# To return a 1D version of self as a view, use the ma.MaskedArray.ravel() method in Numpy
print("
Result...
",maskArr.ravel())

## Output

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

Array type...
int64

Array Dimensions...
2

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

int64

[78 -- 51 56 33 97]