This is fine[*], but I would write either

  a.setValue(0., where=a < 0)

or

  a[(a < 0).value] = 0.


[*] You should never use numpy (np) directly with FiPy objects. It will often 
work, but not always. Instead, do 

  from fipy import numerix as nx
  nx.maximum(...)

and so on.


On Feb 2, 2014, at 7:05 PM, yuan wang <[email protected]> wrote:

> Sorry for the spam. I just found a quick way to do that: 
> 
> np.maximum(a,zeros(n))
> 
> where a is a CellVariable and n is the number of cells.  
> 
> This is an element wise comparison of the two arrays. The bigger value of 
> each comparison will be returned. The result is also a CellVariable. I'm 
> emailing in case others have the same problem. 
> 
> 
> 
> 
> On Sun, Feb 2, 2014 at 11:42 AM, yuan wang <[email protected]> wrote:
> Dear Fipyers, 
> 
> May I know how to quickly assign zero to negative values in a cellvariable? 
> It could be achieved in the following loop format, but I think there might be 
> an easier method to do it, which I'm not aware of. 
> 
> for j in range(n):
>     if a.value(j)>0:
>         a.value(j) =0
> 
> Thank you.
> 
> Best regards,
> Rose
> 
> -- 
> Yuan (Rose) Wang
> PhD Candidate, Tufts University
> Cellphone: 617-699-8006
> 
> 
> 
> -- 
> Yuan (Rose) Wang
> PhD Candidate, Tufts University
> Cellphone: 617-699-8006
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to