Hi, there
I have a practical problem. For some reason, I hope int and float can exist
one array as shown in matlab code.
---------------------------------------------------------------------------
>> x = [2 2.5 3.5; 1 2.6 3.5]
x =
2.0000 2.5000 3.5000
1.0000 2.6000 3.5000
y = x(:,2)
y =
2.5000
2.6000
y(x(:,1))
ans =
2.6000
2.5000
------------------------------------------------------------------------------------
However in python with numpy, the similar code is as follows.
------------------------------------------------------------------------------------------
x = array([[2, 2.5, 3.5],[1, 2.6, 3.5]])
x
array([[ 2. , 2.5, 3.5],
[ 1. , 2.6, 3.5]])
y = x[:,1]
y
array([ 2.5, 2.6])
y.shape=2,1
y
array([[ 2.5],
[ 2.6]])
y[x[:,0],0]
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
IndexError: arrays used as indices must be of integer (or boolean) type
-----------------------------------------------------------------------------------------------------
MATLAB can treat the 1.0,2.00,......as int 1 2,.....
How to realize this matlab code in python? Maybe it exist a simple way.
Please show me .
Thanks in advance
Sam
BTW: I sent this mail to [email protected] at first,
then I receive a mail which suggests me here. If it has already email that
here, I am very sorry about that.
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion