numpy.MaskedArray.ravel()函數用於返回1D版本的自遮罩數組,作為視圖。
用法: numpy.ma.ravel(self, order='C')
參數:
order :[“ C”,“ F”,“ A”,“ K”,可選)默認情況下,使用“ C”索引順序。
->使用此索引順序讀取a的元素。
->'C'表示以C-like順序索引元素,最後一個軸索引更改最快,回到第一個軸索引更改最快。
->“ F”表示以Fortran-like索引順序索引元素,第一個索引更改最快,最後一個索引更改最慢。
->'A'表示如果m在內存中是連續的,則以Fortran-like索引順序讀取元素,否則以C-like順序讀取元素。
->“ K”表示按順序在內存中讀取元素,但當步幅為負時反轉數據。
Return :[MaskedArray]展平的1D蒙版數組。
代碼1:
# Python program explaining
# numpy.MaskedArray.ravel() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input array
in_arr = geek.array([[1, 2], [ 3, -1]])
print ("Input array:", in_arr)
# Now we are creating a masked array.
# by making two entry as invalid.
mask_arr = ma.masked_array(in_arr, mask =[[0, 1], [ 1, 0]])
print ("Masked array:", mask_arr)
# applying MaskedArray.ravel methods to mask array
out_arr = mask_arr.ravel()
print ("1D view of masked array:", out_arr)
輸出:
Input array: [[ 1 2] [ 3 -1]] Masked array: [[1 --] [-- -1]] 1D view of masked array: [1 -- -- -1]
代碼2:
# Python program explaining
# numpy.MaskedArray.ravel() method
# importing numpy as geek
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
# creating input array
in_arr = geek.array([[[ 2e8, 3e-5]], [[ -45.0, 2e5]]])
print ("Input array:", in_arr)
# Now we are creating a masked array.
# by making one entry as invalid.
mask_arr = ma.masked_array(in_arr, mask =[[[ 1, 0]], [[ 0, 0]]])
print ("3D Masked array:", mask_arr)
# applying MaskedArray.ravel methods to mask array
out_arr = mask_arr.ravel()
print ("1D view of masked array:", out_arr)
輸出:
Input array: [[[ 2.0e+08 3.0e-05]] [[-4.5e+01 2.0e+05]]] 3D Masked array: [[[-- 3e-05]] [[-45.0 200000.0]]] 1D view of masked array: [-- 3e-05 -45.0 200000.0]
相關用法
- Python numpy.cov()用法及代碼示例
- Python numpy.copyto()用法及代碼示例
- Python Numpy MaskedArray.any()用法及代碼示例
- Python Numpy MaskedArray.var()用法及代碼示例
- Python Numpy MaskedArray.sum()用法及代碼示例
- Python numpy.issubsctype()用法及代碼示例
- Python Numpy MaskedArray.std()用法及代碼示例
- Python Numpy MaskedArray.mean()用法及代碼示例
- Python Numpy recarray.put()用法及代碼示例
- Python Numpy recarray.ptp()用法及代碼示例
- Python Numpy MaskedArray.all()用法及代碼示例
- Python Numpy MaskedArray.dot()用法及代碼示例
- Python Numpy recarray.all()用法及代碼示例
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 Numpy MaskedArray.ravel() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。