[Numpy-discussion] Finding the same value in List
Wed Apr 17 05:34:45 CDT 2013
> The data type:
> x in ndarray and x[ i ]--> int64
> type(f) --> ' list '
> type( f[ 0 ] ) --> ' tuple '
> type( f[ 0] ) --> 'ndarray'
> type( f[ 0 ][ 0 ][ 0] ) --> 'int64'
> How do you think to avoid diversity if data type in this example? I think
> it is not necessary to get diverse dtype as well as more than 1D array..
That is why I suggested this approach was better ( note the that this is
where() instead of just where() as it was in my first example):
f=[numpy.where(i==ind) for ind in range(len(x))]
type(f) --> list
type(f) --> ndarray
type(f) is meaningless since it is just a single element in an
array. It must be an int type of some sort of since indices have to be int
types. x will be the same dtype as your input array.
You could conceivably change the type of f to a list, but why would you
want to? One of the big advantages of python is that usually it doesn't
matter what the type is. In this case, a numpy ndarray will work the same
as a list in most cases where you would want to use these sorts of indices.
It is possibly to change the ndarray to a list, but unless there is a
specific reason you need to use lists so then it is better not to.
You cannot change the list to an ndarray because the elements of the list
are different lengths. ndarray doesn't support that.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion