當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.ma.append()用法及代碼示例

numpy.ma.append()函數將值附加到數組的末尾。

用法: numpy.ma.append(arr1, arr2, axis = None)
參數:
arr1 :[array_like] Values are appended to a copy of this array.
arr2 :[array_like] Values are appended to a copy of this array. If axis is not specified, arr2 can be any shape and will be flattened before use. Otherwise, it must be of the correct shape.
axis :[int, optional] The axis along which value are appended.
Return :[MaskedArray] A copy of arr1 with arr2 appended to axis. If axis is None, the result is a flattened array.

代碼1:

# Python program explaining 
# numpy.ma.append() function 
  
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma  
  
arr1 = ma.masked_values([1, 2, 3], 3) 
arr2 = ma.masked_values([[4, 5, 6], [7, 8, 9]], 8) 
  
gfg = ma.append(arr1, arr2) 
  
print (gfg)

輸出:

[1 2 -- 4 5 6 7 -- 9]


代碼2:

# Python program explaining 
# numpy.ma.append() function 
  
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma  
  
arr1 = ma.masked_values([1, 2, 3, 4], 2) 
arr2 = ma.masked_values([[5, 6, 7], [8, 9, 10]], 8) 
  
gfg = ma.append(arr1, arr2) 
  
print (gfg)

輸出:

[1 -- 3 4 5 6 7 -- 9 10]



相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.ma.append() function | Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。