Numpy MaskedArray.conjugate () Function | python



numpy.MaskedArray.conjugate() is used to return a complex mate element by element. The conjugate of a complex number is obtained by changing the sign of its imaginary part.

Syntax: numpy.ma.conjugate (arr, out = None, where = True, casting = `same_kind`, order =` K`, dtype = None, subok = True)

Parameters:

arr : [array_like] Input masked array which we want to conjugate.
out: [ndarray, optional] A location into which the result is stored.
 – & gt ; If provided, it must have a shape that the inputs broadcast to.
 – & gt; If not provided or None, a freshly-allocated array is returned.
where: [array_like, optional] Values ​​of True indicate to calculate the ufunc at that position, values ​​of False indicate to leave the value in the output alone.
casting: [`no`, `equiv`, `safe`, `same_kind`, or `unsafe`] Provides a policy for what kind of casting is permitted.
order: The elements of a are read using this index order.
dtype: [dtype, optional] Type of the returned array , as well as of the accumulator in which the elements are multiplied.
subok: Defaults to true. If set to false, the output will always be a strict array, not a subtype.

Return: [ndarray] The complex conjugate of arr.

Code # 1:

# Python program explaining
# numpy.MaskedArray.conjugate () 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 + 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.conjugate
# masked array methods

out_arr = ma.conjugate (mask_arr) 

print ( "conjugate of masked array:" , out_arr) 

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)]] conjugate of masked array: [ [- (2-3j)] [- (-1-2j)] [(5 + 4j) (-3 + 3j)]