Numpy MaskedArray.default_fill_value () Function | python

NumPy | Python Methods and Functions

numpy.MaskedArray.default_fill_value() is used to return the default padding value for the argument object. The default padding value depends on the data type of the input array or the type of the input scalar. If the data type is bool, then the default padding value is True, for int it is 999999, 1.e20 for float, for complex — 1.e20 + 0.j, & # 39;? & # 39; for the object and & # 39; N / A & # 39; for a string.

Syntax: numpy.ma.default_fill_value(obj)

Parameters:
obj: [ndarray, dtype or scalar] The array data-type or scalar for which the default fill value is returned.

Return : [scalar] The default fill value.

Code # 1:

# Python program explaining
# numpy.MaskedArray.default_fill_value () method

  
# import numy as geek
# and numpy.ma module as ma

import numpy as geek 

import numpy.ma as ma 

  
# create input array

in_arr = geek.array ([[ 1 , 2 ], [ 3 , - 1 ], [ 5 , - 3 ]])

print ( "Input array:" , in_arr) 

 
# We now create a masked array.
# invalidate the post.

mask_arr < code class = "keyword"> = ma.masked_array (in_arr,

mask = [[ 1 , 0 ], [ 1 , 0 ], [ 0 , 0 ]]) 

 

print ( "Masked array:" , mask_arr) 

 
# apply MaskedArray.default_fill_value
# masked array methods

out_val = ma.default_fill_value (mask_arr) 

print ( "Default filled value:" , out_val) 

Output:

 Input array: [[1 2] [ 3 -1] [5 -3]] Masked array: [[- 2] [- -1] [5 -3]] Default filled value: 999999 

Code # 2:

# Python program explaining
# numpy. MaskedArray.default_fill_value () method

 
# import numy as a geek
# and the numpy.ma module as ma

import numpy as geek 

import numpy.ma as ma 

 
# create input array

in_arr = geek.array ([[ 1 + 2j , 2 + 3j ],

[ 3 - 2j , - 1 + 2j ],

[ 5 - 4j , - 3 - 3j ]])

print ( "Input array:" , in_arr) 

 
# Now we create a masked array.
# invalidating two entries.

mask_arr = ma.masked_array (in_arr, 

mask = [[[ 1 , 0 ], [ 1 , 0 ], [ 0 , 0 ]]) 

 

print ( "Masked array:" , mask_arr) 

 
# apply MaskedArray.default_fill_value
# masked array methods

out_val = ma.default_fill_value (mask_arr) 

print ( " Default filled value: " , out_val) 

Output :

 Input array: [[1. + 2.j 2. + 3.j ] [3.-2.j -1. + 2.j] [5.-4.j -3.-3.j]] Masked array: [[- - (2 + 3j)] [- (-1 + 2j)] [(5-4j) (-3-3j)]] Default filled value: (1e + 20 + 0j) 




Get Solution for free from DataCamp guru