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

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 :: google.protobuf.Struct example python 
Python :: is there a null data type in python 
Python :: como instalar python en ubuntu 20.04 
Python :: convert exception to string python 
Python :: python global variable unboundlocalerror 
Python :: how to add pagination in discord.py 
Python :: How to check the number of occurence of each character of a given string in python 
Python :: timedelta format python 
Python :: how to round whole numbers in python 
Python :: explode function in python 
Python :: creating a dictionary 
Python :: flask app run 
Python :: matplotlib window size 
Python :: issubclass python example 
Python :: python print in the same line 
Python :: time conversion 
Python :: |safe django 
Python :: torch.utils.data.random_split(dataset, lengths) 
Python :: linked list in merge sort python 
Python :: pandas take entries from other column if column is nan 
Python :: tf dataset 
Python :: python environment variable 
Python :: gil python 
Python :: count pairs with given sum python 
Python :: python in 
Python :: TypeError: create_superuser() missing 1 required positional argument: 
Python :: get user api 
Python :: python pandas sum of series 
Python :: scikit learn 
Python :: python lenght 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =