- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return the transpose of the masked array in NumPy
To return the transpose of the masked array in Python, use the ma.MaskedArray.transpose() method in Numpy.
The axes can be,
None or no argument − reverses the order of the axes.
tuple of ints − i in the j-th place in the tuple means a’s i-th axis becomes a.transpose()’s j-th axis.
n ints − same as an n-tuple of the same ints
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
", maskArr) 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 the transpose of the masked array, use the ma.MaskedArray.transpose() method in Numpy −
print("
Transpose...
",maskArr.T)
Example
# Python ma.MaskedArray - Return the transpose of the masked array 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 maskArr = ma.masked_array(arr, mask =[[0, 1, 0], [ 0, 0, 0]]) print("
Our Masked Array
", maskArr) 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) # To return the transpose of the masked array, use the ma.MaskedArray.transpose() method in Numpy print("
Transpose...
",maskArr.T)
Output
Array... [[78 85 51] [56 33 97]] Array type... int64 Array Dimensions... 2 Our Masked Array [[78 -- 51] [56 33 97]] Our Masked Array type... int64 Our Masked Array Dimensions... 2 Our Masked Array Shape... (2, 3) Elements in the Masked Array... 6 Transpose... [[78 56] [-- 33] [51 97]]
- Related Articles
- Return the length of the masked array in Numpy
- Return a copy of the masked array in NumPy
- Return the mask of a masked array in Numpy
- Return the average of the masked array elements in Numpy
- Return the variance of the masked array elements in Numpy
- Return each element of the masked array rounded in Numpy
- Return the absolute value of a masked Array in NumPy
- Return the standard deviation of the masked array elements in NumPy
- Return the sum along diagonals of the masked array in Numpy
- Return the average of the masked array elements axis 1 in Numpy
- Return the pickle of the masked array as a string in NumPy
- Return array of indices of the maximum values from a masked array in NumPy
- Return array of indices of the minimum values from a masked array in NumPy
- Return the internal state of the masked array for pickling purposes in Numpy
- Return the average of the masked array elements along specific axis in Numpy

Advertisements