<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
thank you Andrea. That is exactly what i was looking for. Great.<br>
Andrea explained what the Matlab code does below. Sorry about the
confusion. <br>
I was under the impression that numpy was leaning very heavily on
Matlab for its syntax and thus i assumed that<br>
Matlab was mostly known for those using numpy.<br>
<br>
Andrea:<br>
you are right about the value 100. It should have been 0.5.<br>
The original code has a different vector which is tested against
100. I tried to simply reproduce the functionality with a random
vector.<br>
Thus the confusion. <br>
<br>
Again, thanks for the input.<br>
matt<br>
<br>
<br>
On 1/25/2011 2:36 PM, Andrea Ambu wrote:
<blockquote
cite="mid:AANLkTik7Lvue5ou1gaxX+pz4XLs8-rpzbE0sc46bYtv3@mail.gmail.com"
type="cite"><br>
<br>
<div class="gmail_quote">On Tue, Jan 25, 2011 at 9:13 PM, Matt
Funk <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:mafunk@nmsu.edu">mafunk@nmsu.edu</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
Hi,<br>
<br>
i am fairly new to python. I was wondering of the following is
do-able<br>
in python:<br>
<br>
1) a = rand(10,1)<br>
2) Y = a<br>
3) mask = Y > 100;<br>
4) Y(mask) = 100;<br>
5) a = a+Y<br>
<br>
</blockquote>
<div><br>
</div>
<div>No. Not like that. </div>
<div><br>
</div>
<div>You do literally:</div>
<div>a = rand(10, 1)</div>
<div>Y = a</div>
<div>mask = Y>100</div>
<div>Y = where(mask, 100, Y)</div>
<div>a = a+Y</div>
<div><br>
</div>
<div><br>
</div>
<div>More Pythonically:</div>
<div>a = rand(10, 1)</div>
<div>a = where(a > 100, a + 100, a + a)</div>
<div><br>
</div>
<div><br>
</div>
<div>For those who don't speak Matlab:</div>
<div><br>
</div>
<div>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
1) a = rand(10,1) ; generates a 10x1 matrix for random number
0 < n < 1<br>
2) Y = a <br>
3) mask = Y > 100; similar to: mask = [i>100 for i in Y]<br>
4) Y(mask) = 100; sets to 100 elements of Y with index i for
which mask[i] = True<br>
5) a = a+Y ; sums the two matrices element by element (like
you do in linear algebra) </div>
<div><br>
</div>
<div><br>
</div>
<div>Anyway... rand generates number from 0 up to 1 (both in
python and matlab)... when are they > 100? </div>
<div><br>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
0.8ex; border-left: 1px solid rgb(204, 204, 204);
padding-left: 1ex;">
Basically i am getting stuck on line 4). I was wondering if it
is<br>
possible or not with python?<br>
(The above is working matlab code)<br>
<br>
thanks<br>
matt<br>
<font color="#888888">--<br>
<a moz-do-not-send="true"
href="http://mail.python.org/mailman/listinfo/python-list"
target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote>
</div>
<br>
</blockquote>
<br>
</body>
</html>