Change language

Numpy MaskedArray.common_fill_value () Function | python

| |

numpy.MaskedArray.common_fill_value() is used to return the total padding value between two masked arrays. If arr1.fill_value == arr2.fill_value then the fill value is returned, otherwise None is returned.

Syntax: numpy .ma.common_fill_value (arr1, arr2)

Parameters:
arr1, arr2: [MaskedArray] The masked arrays for which to compare fill values.

Return: [scalar or None] The common fill value or None.

Code # 1:

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

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

import numpy as geek 

< p> import numpy.ma as ma 

 
# create input arrays

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

print ( " 1st Input array: " , in_arr1) 

  

in_arr2 = geek.array ([[ 10 , 20 ], [ 30 , - 10 ], [ 50 , - 30 ]])

print ( "2nd Input array: " , in_arr2) 

  
# We are now creating masked arrays.
# invalidating the post.

mask_arr1 = ma.masked_array (in_arr1, mask = [[ 1 , 0 ], [ 1 , 0 ] , [ 0 , 0 ]],

  fill_value = 5

print ( "1st Masked array:" , mask_arr1) 

 

mask_arr2 = ma.masked_array (in_arr2, mask = [[ 1 , 1 ], [ 1 , 0 ], [ 0 , 0 ]], 

fill_value = 5

print ( "2nd Masked array:" , mask_arr2) 

  
# apply MaskedArray.common_fill_value
# methods of the masked array

out_arr = ma.common_fill_value (mask_arr1, mask_arr2) 

print ( "common filled value:" , out_arr) 

Output:

 1st Input array: [[1 2] [3 -1] [5 -3]] 2nd Input array: [[ 10 20] [30 -10] [50 -30]] 1st Masked array: [[- 2] [- -1] [5 -3]] 2nd Masked array: [[- -] [- -10] [50 -30]] common filled value: 5 

Code # 2:

 

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

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

import numpy as geek 

import numpy.ma as ma 

  
# create input arrays

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

print ( "1st Input array:" , in_arr1) 

 

in_arr2 = geek.array ([[ 10 , 20 ], [ 30 , - 10 ], [ 50 , - 30 ]])

print ( "2nd Input array:" , in_arr2) 

 
# We are now creating masked arrays.
# invalidating the post.

mask_arr1 = ma.masked_array (in_arr1, mask = [[ 1 , 0 ], [ 1 , 0 ], [ 0 , 0 ]],

fill_value = 5

print ( " 1st Masked array: " , mask_arr1) 

 

mask_arr2 = ma.masked_array (in_arr2, mask = [[ 1 , 1 ], [ 1 , 0 ], [ 0 , 0 ]],

fill_value = 10

print ( "2nd Masked array:" , mask_arr2) 

 
# apply MaskedArray.common_fill_value
# masked array methods

out_arr = ma.common_fill_value (mask_arr1, mask_arr2) 

print ( "common filled value:" , out_arr) 

Exit:

 1st Input array: [[1 2] [3 -1] [ 5 -3]] 2nd Input array: [[10 20] [30 -10] [50 -30]] 1st Masked array: [[- 2] [- -1] [5 -3]] 2nd Masked array : [[- -] [- -10] [50 -30]] common filled value: None 

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically