A
Andrea Ambu
I replied to Matt only ARGH!
---------- Forwarded message ----------
From: Andrea Ambu <[email protected]>
Date: 25 January 2011 22:36
Subject: Re: numpy/matlab compatibility
To: Matt Funk <[email protected]>
No. Not like that.
You do literally:
a = rand(10, 1)
Y = a
mask = Y>100
Y = where(mask, 100, Y)
a = a+Y
More Pythonically:
a = rand(10, 1)
a = where(a > 100, a + 100, a + a)
For those who don't speak Matlab:
1) a = rand(10,1) ; generates a 10x1 matrix for random number 0 < n < 1
2) Y = a
3) mask = Y > 100; similar to: mask = [i>100 for i in Y]
4) Y(mask) = 100; sets to 100 elements of Y with index i for which
mask = True
5) a = a+Y ; sums the two matrices element by element (like you do in
linear algebra)
Anyway... rand generates number from 0 up to 1 (both in python and
matlab)... when are they > 100?
---------- Forwarded message ----------
From: Andrea Ambu <[email protected]>
Date: 25 January 2011 22:36
Subject: Re: numpy/matlab compatibility
To: Matt Funk <[email protected]>
Hi,
i am fairly new to python. I was wondering of the following is do-able
in python:
1) a = rand(10,1)
2) Y = a
3) mask = Y > 100;
4) Y(mask) = 100;
5) a = a+Y
No. Not like that.
You do literally:
a = rand(10, 1)
Y = a
mask = Y>100
Y = where(mask, 100, Y)
a = a+Y
More Pythonically:
a = rand(10, 1)
a = where(a > 100, a + 100, a + a)
For those who don't speak Matlab:
1) a = rand(10,1) ; generates a 10x1 matrix for random number 0 < n < 1
2) Y = a
3) mask = Y > 100; similar to: mask = [i>100 for i in Y]
4) Y(mask) = 100; sets to 100 elements of Y with index i for which
mask = True
5) a = a+Y ; sums the two matrices element by element (like you do in
linear algebra)
Anyway... rand generates number from 0 up to 1 (both in python and
matlab)... when are they > 100?