# [SciPy-user] Re[2]: Unexpected behavior (bug?): scipy x Numeric.argmin

krivilli at unberwoot.net krivilli at unberwoot.net
Mon Oct 11 20:51:58 CDT 2004

```rkern at ucsd.edu wrote:
=======================
> SciPy alters the comparison functions to return UInt8 arrays.

-Thank you! That's it.

> In [1]: tmp = array([0,0,1,1], UInt8)

> In [2]: tmp
> Out[2]: NumPy array, format: long
> [0 0 1 1]

> In [3]: -tmp
> Out[3]: NumPy array, format: long
> [  0   0 255 255]

> You can work around this by casting tmp to some signed type before
> passing it to argmin().

> However, I believe you should be using the functions
> logical_not(alltrue(tmp)) instead of argmin(tmp). Those functions
> accurately represent the semantics of the operation you want to perform.

-Although this way should work out with the example I gave you, it wont
work for all cases I'm dealing with, cuz i'm interested on the index of
the element in the array, and not only in a boolean result.

-For example:

tmp <- array([[0, 0, 0, 0, 0, 1, 1, 1],
[1, 1, 0, 0, 0, 1, 1, 1],
[1, 1, 1, 0, 1, 0, 1, 1],
[0, 0, 0, 1, 1, 0, 0, 0]])

x <- Numeric.argmin(array(tmp,Numeric.Int),0)

x -> array([0, 0, 0, 0, 0, 2, 3, 3])

y <- scipy.logical_not(scipy.alltrue(tmp))

y -> array([1, 1, 1, 1, 1, 1, 1, 1])

-In this case what im looking for is [0, 0, 0, 0, 0, 2, 3, 3], which are
the indexes (lines) of the 1st minimum value on a column (represented by a
'0').

-Thanks again.

regards,

-- roberto (krivilli)

```