Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

np.where

>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.where(a < 5, a, 10*a)
array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])
Comment

numpy where

import numpy as np

# Return elements chosen from x or y depending on condition.
a = np.arange(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
single_where = np.where((a<5),-1,a) # [-1, -1, -1, -1, -1,  5,  6,  7,  8,  9]
multiple_where = np.where((a<5),-1,np.where((a>5),0,a)) # [-1, -1, -1, -1, -1,  5,  0,  0,  0,  0]
Comment

numpy.where

Parameters:
condition : When True, yield x, otherwise yield y.
x, y : Values from which to choose. x, y and condition need to be broadcastable to some shape.

Returns:
out : [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.
Comment

np where and

In [1]: my_array = arange(10)

In [2]: where((my_array > 3) & (my_array < 7))
Out[2]: (array([4, 5, 6]),)
Comment

np.where

np.where([[True, False], [True, True]],
...          [[1, 2], [3, 4]],
...          [[9, 8], [7, 6]])
array([[1, 8],
       [3, 4]])
Comment

numpy.where

>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.where(a < 5, a, 10*a)
array([ 0,  1,  2,  3,  4, 50, 60, 70, 80, 90])
Comment

PREVIOUS NEXT
Code Example
Python :: python .nlargest 
Python :: any in python 
Python :: how to get a summary of a column in python 
Python :: python run powershell command and get output 
Python :: overload operator python 
Python :: - inf in python 
Python :: scrapy proxy pool 
Python :: python trim leading whitespace 
Python :: xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 0 
Python :: get all files in pc python 
Python :: pandas resample groupby 
Python :: splitting column values in pandas 
Python :: views.py django 
Python :: python create a dictionary of integers 
Python :: unique value python 
Python :: python list Clear the list content 
Python :: laplace transform python 
Python :: how to change int to four decimal places in python 
Python :: scrapy get inside attribute value 
Python :: pandas dataframe first rows 
Python :: python string cut last n characters 
Python :: import path in django 
Python :: python max function recursive 
Python :: install python3.6 in linux 
Python :: logical operators pandas 
Python :: replace comma with dot in column pandas 
Python :: subprocess.popen no output 
Python :: python binary search 
Python :: higlight words in python 
Python :: distance of a point from a line python 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =