At bit OT, but I am new to numpy. The help for np.where says:
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.
If on
okay Todd, I got it.
There are some reasons why I preferred asking that question. Let me explain:
I am using Excel data which contains 3 columns and say 12 rows to process some
simple data.
What I want to do with the code you provided is that In the first column A has
data that indicates the sa
>
> The data type:
> x in ndarray and x[ i ]--> int64
> type(f) --> ' list '
> type( f[ 0 ] ) --> ' tuple '
> type( f[ 0][0] ) --> 'ndarray'
> type( f[ 0 ][ 0 ][ 0] ) --> 'int64'
>
> How do you think to avoid diversity if data type in this example? I
Okay Todd,
In both results, I got the proper values.. for me indices are important also
counting.
From your code:
let's say function--> sort_out(data):
x , f = sort_out( data )
The data type:
x in ndarray and x[ i ]--> int64
type(f) --> ' list '
type( f[ 0 ] )
On Wed, 2013-04-17 at 13:32 +0400, Happyman wrote:
> Hi Todd,
> Greaaat thanks for your help.. By the way, the first one (I think) is
> much simpler.. I tested it and ,of course, it is 1D, but it is also a
> good idea to consider it for Ndimensional.
> I prefer the first one! Do you you think first
Hi Todd,
Greaaat thanks for your help.. By the way, the first one (I think) is much
simpler.. I tested it and ,of course, it is 1D, but it is also a good idea to
consider it for Ndimensional.
I prefer the first one! Do you you think first version is okay to use?
Среда, 17 апреля 2013, 11:02 +
On Wed, Apr 17, 2013 at 10:46 AM, Todd wrote:
> x,i=numpy.unique(y, return_inverse=True)
> f=[numpy.where(i==ind) for ind in range(len(x))]
>
>
>
A better version would be (np.where returns tuples, but we don't want
tuples):
x,i=numpy.unique(y, return_inverse=True)
f=[numpy.where(i==ind)[0] for
x,i=numpy.unique(y, return_inverse=True)
f=[numpy.where(i==ind) for ind in range(len(x))]
x will give you the list of unique values, and f will give you the indices
of each corresponding value in x. So f[0] is the indices of x[0] in y.
To explain, unique in this form gives two outputs, a sorted,
Hello,
I have had encountered some problem while I was trying to create the following
code which finds number of the same values and indexes in an array or list.
Here is the code:
y = [ 1, 12, 3, 3, 5, 1, 1, 34, 0, 0, 1, 5]
OR
y = array( [ 1, 12, 3, 3, 5, 1, 1, 34, 0, 0, 1, 5 ]