numpy.ma.choose() function - Python Last Updated : 05 May, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report numpy.ma.choose() function use an index array to construct a new array from a set of choices. Given an array of integers and a set of n choice arrays, this method will create a new array that merges each of the choice arrays. Where arr value in arr is i, the new array will have the value that choices[i] contains in the same place. Syntax : numpy.ma.choose(arr, choices, out = None, mode = 'raise') Parameters : arr : [ndarray of ints] This array must contain integers in [0, n-1], where n is the number of choices. choices : [sequence of arrays] Choice arrays. The index array and all of the choices should be broadcastable to the same shape. out : [array, optional] If provided, the result will be inserted into this array. It should be of the appropriate shape and dtype. mode : [{‘raise’, ‘wrap’, ‘clip’}, optional] Specifies how out-of-bounds indices will behave. ‘raise’: raise an error. ‘wrap’: wrap around. ‘clip’: clip to the range. Return : A new array that merges each of the choice arrays. Code #1 : Python3 # Python program explaining # numpy.ma.choose() function # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma choice = geek.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) arr = geek.array([2, 1, 0]) gfg = geek.ma.choose(arr, choice) print (gfg) Output : [3 2 1] Code #2 : Python3 # Python program explaining # numpy.ma.choose() function # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma choice = geek.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]) arr = geek.array([0, 1, 2]) gfg = geek.ma.choose(arr, choice) print (gfg) Output : [1 2 3] Comment More infoAdvertise with us Next Article numpy.ma.choose() function - Python S sanjoy_62 Follow Improve Article Tags : Machine Learning Python-numpy python Python Numpy-Masked Array Practice Tags : Machine Learningpython Similar Reads numpy.ma.filled() function - Python numpy.ma.filled() function return input as an array with masked data replaced by a fill value. If arr is not a MaskedArray, arr itself is returned. If arr is a MaskedArray and fill_value is None, fill_value is set to arr.fill_value. Syntax : numpy.ma.filled(arr, fill_value = None) Parameters : arr : 1 min read numpy.matrix.A() function - Python numpy.matrix.A() function return self as an ndarray object. Syntax : numpy.matrix.A() Parameters : None Return : [ndarray] Return self as an ndarray. Code #1 : Python3 # Python program explaining # numpy.matrix.A() function # importing numpy as geek import numpy as geek mat = geek.matrix(geek.arange 1 min read numpy.ma.where() function - Python numpy.ma.where() function return a masked array with elements from x or y, depending on condition. Syntax : numpy.ma.where(condition, x, y) Parameter : condition : [array_like, bool] Where True, yield x, otherwise yield y. x, y : [array_like, optional] Values from which to choose. x, y and condition 1 min read numpy.ma.mask_or() function | Python numpy.ma.mask_or() function combine two masks with the logical_or operator. The result may be a view on m1 or m2 if the other is nomask (i.e. False). Syntax : numpy.ma.mask_or(m1, m2, copy = False, shrink = True) Parameters : m1, m2 : [ array_like] Input masks. copy : [bool, optional] If copy is Fal 2 min read numpy.ma.fix_invalid() function | Python numpy.ma.fix_invalid() function return input with invalid data masked and replaced by a fill value. Where invalid data means values of nan, inf, etc. Syntax : numpy.ma.fix_invalid(arr, mask = False, copy = True, fill_value = None) Parameter : arr : [array_like] Input array. mask : [sequence, optiona 2 min read Like