[Numpy-discussion] Fill a particular value in the place of number satisfying certain condition by another number in an array.

eat e.antero.tammi at gmail.com
Mon Aug 1 12:23:04 EDT 2011


Hi

On Mon, Aug 1, 2011 at 3:14 PM, Jeffrey Spencer <jeffspencerd at gmail.com>wrote:

>  Depends where it is contained but another option is and I find it to
> typically be faster:
>
> B = zeros(A.shape)
> maximum(A,B,A)
>
Since maximum(.) can handle broadcasting
maximum(A, 0, A)
will be even faster.

-eat

>
>
> On 08/01/2011 07:31 PM, dileep kunjaai wrote:
>
> Dear sir,
>    How can we fill a particular value in the place of number satisfying
> certain condition by another number in an array.
>
>
> Example:
>  A=[[[  9.42233087e-42  - 4.71116544e-42   0.00000000e+00 ...,
> 1.48303127e+01
>      1.31524124e+01   1.14745111e+01]
>   [  3.91788793e+00   1.95894396e+00   0.00000000e+00 ...,   1.78252487e+01
>      1.28667984e+01   7.90834856e+00]
>   [  7.83592510e+00   -3.91796255e+00   0.00000000e+00 ...,
> 2.08202991e+01
>      1.25811749e+01   4.34205008e+00]
>   ...,
>   [  -8.51249974e-03   7.00901222e+00   -1.40095119e+01 ...,
> 0.00000000e+00
>      0.00000000e+00   0.00000000e+00]
>   [  4.26390441e-03   3.51080871e+00   -7.01735353e+00 ...,
> 0.00000000e+00
>      0.00000000e+00   0.00000000e+00]
>   [  0.00000000e+00   0.00000000e+00   0.00000000e+00 ...,   0.00000000e+00
>      0.00000000e+00   0.00000000e+00]]
>
>  [[  9.42233087e-42   -4.71116544e-42   0.00000000e+00 ...,
> 8.48242474e+00
>      7.97146845e+00   7.46051216e+00]
>   [  5.16325808e+00   2.58162904e+00   0.00000000e+00 ...,   8.47719383e+00
>      8.28024673e+00   8.08330059e+00]
>   [  1.03267126e+01   5.16335630e+00   0.00000000e+00 ...,   8.47196198e+00
>      8.58903694e+00   8.70611191e+00]
>   ...,
>   [  0.00000000e+00   2.74500012e-01   5.49000025e-01 ...,   0.00000000e+00
>      0.00000000e+00   0.00000000e+00]
>   [  0.00000000e+00   1.37496844e-01   -2.74993688e-01 ...,
> 0.00000000e+00
>      0.00000000e+00   0.00000000e+00]
>   [  0.00000000e+00   0.00000000e+00   0.00000000e+00 ...,   0.00000000e+00
>      0.00000000e+00   0.00000000e+00]]
>
>  [[  9.42233087e-42   4.71116544e-42   0.00000000e+00 ...,   1.18437748e+01
>      9.72778034e+00   7.61178637e+00]
>   [  2.96431869e-01   1.48215935e-01   0.00000000e+00 ...,   1.64031239e+01
>      1.32768812e+01   1.01506386e+01]
>   [  5.92875004e-01   2.96437502e-01   0.00000000e+00 ...,   2.09626484e+01
>      1.68261185e+01   1.26895866e+01]
>   ...,
>   [  1.78188753e+00   -8.90943766e-01   0.00000000e+00 ...,
> 0.00000000e+00
>      1.27500005e-03   2.55000009e-03]
>   [  9.34620261e-01   -4.67310131e-01   0.00000000e+00 ...,
> 0.00000000e+00
>      6.38646539e-04   1.27729308e-03]
>   [  8.43000039e-02   4.21500020e-02   0.00000000e+00 ...,   0.00000000e+00
>      0.00000000e+00   0.00000000e+00]]]
>   A contain some negative value i want to change the negative numbers to
> '0'.
> I used 'masked_where', command but I failed.
>
>
>
> Please help me
>
> --
> DILEEPKUMAR. R
> J R F, IIT DELHI
>
>
>
> _______________________________________________
> NumPy-Discussion mailing listNumPy-Discussion at scipy.orghttp://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110801/ac28eaea/attachment.html>


More information about the NumPy-Discussion mailing list