El dl 23 de 04 del 2007 a les 12:47 -0400, en/na Anne Archibald va
escriure:
> On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote:
>
> > Note that in addition of the bitwise operators, you can use the "logical_"
> > functions. OK, you'll still end up w/ temporaries, but I wonder whether
> > there
>
On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote:
> Note that in addition of the bitwise operators, you can use the "logical_"
> functions. OK, you'll still end up w/ temporaries, but I wonder whether there
> couldn't be some tricks to bypass that...
If you're really determined not to make many t
Robert Kern wrote:
> Certainly. How about this?
>
> mask = (a<0)
> a[mask] = numpy.random.normal(0, 1, size=mask.sum())
>
That's slick. I believe it's precisely what I'm after.
Appreciate it,
-Mark
___
Numpy-discussion mailing list
Numpy-discussion
> When you say "no python temps" I guess you mean, no temporary
> *variables*? If I understand correctly, this allocates a temporary
> boolean array to hold the result of "a<0".
Indeed, hence my precising "no *python* temps". There still be a tmp created
at one point or another (if I'm not mista
> > Have you tried nonzero() ?
>
> Nonzero isn't quite what I'm after, as the tests are more complicated
> than what I illustrated in my example.
Tests such as (a<0)&(b>1) will give you arrays of booleans. The nonzero give
you where the two conditions are met (viz, where the results is True, or 1
On 23/04/07, Pierre GM <[EMAIL PROTECTED]> wrote:
> Have you tried nonzero() ?
>
> a[a<0] = numpy.random.normal(0,1)
>
> will put a random number from the normal distribution where your initial a is
> negative. No Python loops needed, no Python temps.
When you say "no python temps" I guess you me
Mark.Miller wrote:
> Pierre GM wrote:
>> a[a<0] = numpy.random.normal(0,1)
>
> This is a neat construct that I didn't realize was possible. However,
> it has the undesirable (in my case) effect of placing a single new
> random number in each locations where a<0. While this could work, I
> id
Excellent suggestions...just a few comments:
Pierre GM wrote:
> On Monday 23 April 2007 10:37:57 Mark.Miller wrote:
>> Greetings:
>>
>> In some of my code, I need to use large matrix of random numbers that
>> meet specific criteria (i.e., some random numbers need to be removed and
>> replaces with
Oh, I pressed "send" too early.
Just an addition:
numpy.where creates a new array from some condition. If you only want to
change elements of an existing array that satisfies a given condition,
indexing is far more efficient: no temporary is created. Hence the suggestion
of
a[a<0]
_
On Monday 23 April 2007 10:37:57 Mark.Miller wrote:
> Greetings:
>
> In some of my code, I need to use large matrix of random numbers that
> meet specific criteria (i.e., some random numbers need to be removed and
> replaces with new ones).
>
> I have been working with .any() and .where() to facili
Greetings:
In some of my code, I need to use large matrix of random numbers that
meet specific criteria (i.e., some random numbers need to be removed and
replaces with new ones).
I have been working with .any() and .where() to facilitate this process.
In the code below, .any() is used in a w
11 matches
Mail list logo