mango.map_element_values

mango.map_element_values(input, ufunc, mtype=None, dtype=None, use1to1cache=True)

Maps each element value if input array to new value calculated by ufunc.

Parameters:
  • input (mango.Dds) – Elements of this array are mapped to new values via the ufunc argument.
  • ufunc (callable object) – Unary function which accepts a input.dtype argument and returns a dtype (or mtype.dtype) value.
  • mtype (mango.mtype or str) – The mango.mtype of the returned mango.Dds object.
  • dtype (numpy.dtype or str) – The numpy.dtype of the returned mango.Dds array.
  • use1to1cache (bool) – If True, an internal lookup table is kept which saves multiple calls of the ufunc function for the same argument. Can excessively use memory (for float data types, say) and is not correct if the ufunc function is not a 1-to-1 mapping.
Return type:

mango.Dds

Returns:

Array with elements mapped as per ufunc mapping.

Example:

import mango
import mango.data
import math

def cubed_root_func(x):
   return math.pow(x,1.0/3.0)

srcDds  = mango.data.gaussian_noise(shape=(64,128,128), mean=2000, stdd=10, dtype="int32")
sqrdDds = mango.map_element_values(srcDds, lambda x: x*x)
sqrtDds = mango.map_element_values(srcDds, lambda x: math.sqrt(x), dtype="float32")
cubdDds = mango.map_element_values(srcDds, cubed_root_func, mtype="tomo_float")

Previous topic

mango.copy_non_masked

Next topic

Fundamental Data Structures and Functions (mango.core)

This Page