# [Numpy-discussion] calculating matrix values at particular indices?

Sasha ndarray at mac.com
Thu Feb 16 19:16:07 CST 2006

```You should make t and x the same type: either add dtype='f' to arange
or change dtype='f' to dtype='d' in zeros.

On 2/16/06, Brian Blais <bblais at bryant.edu> wrote:
> Hello,
>
> In my attempt to learn python, migrating from matlab, I have the following problem.
> Here is what I want to do, (with the wrong syntax):
>
> from numpy import *
>
> t=arange(0,20,.1)
> x=zeros(len(t),'f')
>
> idx=where(t>5)
> tau=5
> x[idx]=exp(-t[idx]/tau)  # <---this line is wrong (gives a TypeError)
>
> #------------------
>
> what is the best way to replace the wrong line with something that works: replace all
> of the values of x at the indices idx with exp(-t/tau) for values of t at indices idx?
>
> I do this all the time in matlab scripts, but I don't know that the pythonic
> preferred method is.
>
>
>
>              thanks,
>
>                  bb
>
>
> --
> -----------------
>
>              bblais at bryant.edu
>              http://web.bryant.edu/~bblais
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
> for problems?  Stop!  Download the new AJAX search engine that makes
> searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>

```

More information about the Numpy-discussion mailing list