numpy.select() function | Python
numpy.select()() function return an array drawn from elements in choicelist, depending on conditions.
Syntax : numpy.select(condlist, choicelist, default = 0)
condlist : [list of bool ndarrays] It determine from which array in choicelist the output elements are taken. When multiple conditions are satisfied, the first one encountered in condlist is used.
choicelist : [list of ndarrays] The list of arrays from which the output elements are taken. It has to be of the same length as condlist.
default : [scalar, optional] The element inserted in output when all conditions evaluate to False.
Return : [ndarray] An array drawn from elements in choicelist, depending on conditions.
Code #1 :
[ 0, 1, 2, 0, 0, 125, 216, 343]
Code #2 :
[ 0, 1, 2, 3, 0, 0, 0, 49]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course