NumPy 1.14 - numpy.where()
numpy.where

numpy.where
-
numpy.where(condition[, x, y])
-
रिटर्न तत्व, या तो
x
याy
,condition
आधार पर।यदि केवल
condition
दी गई है, तोcondition.nonzero()
लौटें।पैरामीटर: शर्त : array_like, बूल
जब सही है, उपज
x
, अन्यथा उपजy
।x, y : array_like, वैकल्पिक
मान जिससे चयन करना है।
x
,y
औरcondition
को कुछ आकार में प्रसारित करने की आवश्यकता है।यह दिखाता है: बाहर : ndarray या tdle of ndarrays
यदि
x
औरy
दोनों को निर्दिष्ट किया जाता है, तो आउटपुट सरणी मेंx
तत्व होते हैं जहाँcondition
सत्य होती है, औरy
कहीं और तत्व।यदि केवल
condition
दी गई है, तो tuplecondition.nonzero()
लौटें, जहाँ परcondition
सत्य हैं।टिप्पणियाँ
यदि
x
औरy
दिए गए हैं और इनपुट सरणियाँ 1-D हैं, तो इसके बराबर है:[xv if c else yv for (c,xv,yv) in zip(condition,x,y)]
उदाहरण
>>> np.where([[True, False], [True, True]], ... [[1, 2], [3, 4]], ... [[9, 8], [7, 6]]) array([[1, 8], [3, 4]])
>>> np.where([[0, 1], [1, 0]]) (array([0, 1]), array([1, 0]))
>>> x = np.arange(9.).reshape(3, 3) >>> np.where( x > 5 ) (array([2, 2, 2]), array([0, 1, 2])) >>> x[np.where( x > 3.0 )] # Note: result is 1D. array([ 4., 5., 6., 7., 8.]) >>> np.where(x < 5, x, -1) # Note: broadcasting. array([[ 0., 1., 2.], [ 3., 4., -1.], [-1., -1., -1.]])
x
के तत्वों के सूचकांकों का पता लगाएं जोgoodvalues
।>>> goodvalues = [3, 4, 7] >>> ix = np.isin(x, goodvalues) >>> ix array([[False, False, False], [ True, True, False], [False, True, False]]) >>> np.where(ix) (array([1, 1, 2]), array([0, 1, 1]))