Im trying to understand numpy where condition.
>>> import numpy as np
>>> x = np.arange(9.).reshape(3, 3)
>>> x
array([[ 0., 1., 2.],
[ 3., 4., 5.],
[ 6., 7., 8.]])
>>> np.where( x > 5 )
(array([2, 2, 2]), array([0, 1, 2]))
IN the above case, what does the output actually mean, array([0,1,2]) I actually see in the input what is array([2,2,2])
Md Johirul Islam :
Th first array indicates the row number and the second array indicates the corresponding column number.\n\nIf the array is following:\n\narray([[ 0., 1., 2.],\n [ 3., 4., 5.],\n [ 6., 7., 8.]])\n\n\nThen the following\n\n(array([2, 2, 2]), array([0, 1, 2]))\n\n\nCan be interpreted as\n\narray(2,0) => 6\narray(2,1) => 7\narray (2,2) => 8\n",
2018-04-19T23:20:20
NaN :
You might also want to know where those values appear visually in your array. In such cases, you can return the array's value where the condition is True and a null value where they are false. In the example below, the value of x is returned at the position where x>5, otherwise assign -1.\n\nx = np.arange(9.).reshape(3, 3)\nnp.where(x>5, x, -1)\narray([[-1., -1., -1.],\n [-1., -1., -1.],\n [ 6., 7., 8.]])\n",
2018-04-20T04:58:49