numpy where

Solutions on MaxInterview for numpy where by the best coders in the world

showing results for - "numpy where"
Elyas
13 Jun 2018
1>>> a = np.arange(10)
2>>> a
3array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
4>>> np.where(a < 5, a, 10*a)
5array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])
6
Debora
14 Apr 2019
1import numpy as np
2
3# Return elements chosen from x or y depending on condition.
4a = np.arange(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
5single_where = np.where((a<5),-1,a) # [-1, -1, -1, -1, -1,  5,  6,  7,  8,  9]
6multiple_where = np.where((a<5),-1,np.where((a>5),0,a)) # [-1, -1, -1, -1, -1,  5,  0,  0,  0,  0]
Micaela
22 Aug 2019
1Parameters:
2condition : When True, yield x, otherwise yield y.
3x, y : Values from which to choose. x, y and condition need to be broadcastable to some shape.
4
5Returns:
6out : [ndarray or tuple of ndarrays] If both x and y are specified, the output array contains elements of x where condition is True, and elements from y elsewhere.
queries leading to this page
np where numpynp conditionnp whereznumpy condition arraynp where x 3cynumpy where conditionnumpy checking array indices where conditionnp where andnp where python examplenumpy where pythonwhat does np where dowhere 28 29 numpypython wherenp where example pythonpoco where innumpy array 5bcondition 5dnp where andhow to use numpy whereusing np wherenumpy with conditionwhere 28 29 numpynp where gives list np where numpy arraynp wheerusing or in np where where 28 29np where example set valuenp where to listpython np where 28 29use numpy where to return an arrayhow to use numpy wherewhere function in python numpy where arraynumpy where functionp array ifstore np where in listnpmpy wherenp where numpynumpy array where conditionnp where function in pythonnumpy where 28 29np where python 3where 28 29numpy condition2d numpy array where condition axis 0np where 28 3d 3d 29 where in pythonwhere example numpynp wherehttp 3a 2f 2fnumpy wherenp where conditioncondition numpy wherenp where in pythonarray 5bnp where 28 29 5d pythonnumpy whereinnumpy find wherenp 2cwherenp where in python numpynp where 28 29 np array wherewhat is np where in pythonnp where inside np wherenp where 28 29how to use np wherenp where pythona numpy array conditionsnp where python listwhere python function 3awhere 28 29np where with variable value pythonlambda condition np wherenp condition valuespython wherenp where usagepython np where examplenp where 22 3d 3d 22np where in pythnnp where with 5 or more clause in pythonnumpy where examplenumpy where in pythonhow to use np where functionnp ndwhere where pythoncondition numpy arraypython array np wherenp where examplenp where truenumpy where 1 60numpy wherenp where clausenp where with vector condition pythonnp where using andnp where 5cnp where pandasnp where ndpython np wherewhere python arraywhere on numpy arraywhere nppython np where hunor condition in np wherewhere in python numpy np wherepython numpy wherenp whichnp where findnumpy where functionnp where for pandasnp where 28 pandas np wherewhere function in numpywhere function pythonuse np wherenumpy array wherenp where on matrixor fucntion in np wherenp where functionnp where syntaxnp where 3fif in array python np wherepython np where 28 29 5b 5dnp conditionalwhich np pythonnumpy where functionnp where syntax in pythonwhere 28 29 pythonnp wherepython np array wherenp where axis how to apply np where in pythonpython where functionnp which pythonnp xherenp where 28a 3c 3 29numpy wherenp where with vectors pythonnp where in numpynp where np where for 2 conditionspython np where innp where without x ynp where pythonnp where functionnumpy where documentationnp where to listnp where 23numpy array use condition inside 5b 5d inclusion exclusion numpy where in pythonnp where y 3d 3d1np where arraynp wheenp ifpython numpy wherenp where in pythonnumpy where 28 29 where in numpypython numpy where andnp where array matrixand condition in numpy wherewhere in pythonnp where list pythonpython np where ornp where numpy examplenp where 5b0 5dnumpy np wherewhere numpy pythonnump wherenp where 26 pythonwhere in numpynumpy array where condition axis 0numpy wherenp where 28 29 functionnp array wherenumpy where 5cnumpy function wherenumpy where 2awhere pythonnp where documentationnumpy where 28 29 5b0 5dnuimpy where np where y 3e 3d 0 1 0np where 28 29 5b 5d 5b 5d in pythonhow to use np where in pythonnumpy array where truenumpy np where in pythonpythin np wherenp where python3condition inside ndarry np pythonnumpy where examplenp wherenp where 5b 3a 3a 5dnumpy np where syntaxnumpy where 28 29anumpy where without conditionnp where how to usenp where 3d 3dnumpy where documentationwirte if in numpy wherenumpy where implementation where numpyhow to use np where in numpy arraynumpy wherenp where examplewhere numpynp arg python conditionnp where np arraynumpy where 1np whgerenumpy whreernp where 28how to use numpy where in pythonuse 22where 22 in numpynp which where 28 29 pythonnp wherenp where 27condition in numpy wherenumpy wherenumpy where 28np where pythonnp where examplespython np where in to np whereusing and or or with np wherenp wherewhere 28 29 in pythoncondition numpy araywhat does np where 28 29 do 3fwhere 28i 3d 3d i 29np where 28 29 in pythonnp wher 28using and in np wherenumpy where