[Numpy-discussion] Replacing colours in numpy array
Frank Peacock
frank@gis4weather....
Fri Apr 10 09:18:52 CDT 2009
Hello
I have a numpy array that I obtained from a converted RGBA gif image. I have
tried to replace some colours with different ones using the where condition
but have a problem with dimensions.
If I use b=where(a==0,255,a) where a is a numpy array from an image it does
replace components of the RGB values in each pixel but it fails if I try
b=where(a==(0,0,0,255),(255,255,255,255),a) with incorrect dimension error.
Could you please help?
Thanks
Frank
-----Original Message-----
From: numpy-discussion-bounces@scipy.org
[mailto:numpy-discussion-bounces@scipy.org] On Behalf Of
numpy-discussion-request@scipy.org
Sent: 10 April 2009 08:18
To: numpy-discussion@scipy.org
Subject: Numpy-discussion Digest, Vol 31, Issue 24
Send Numpy-discussion mailing list submissions to
numpy-discussion@scipy.org
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.scipy.org/mailman/listinfo/numpy-discussion
or, via email, send a message with subject or body 'help' to
numpy-discussion-request@scipy.org
You can reach the person managing the list at
numpy-discussion-owner@scipy.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Numpy-discussion digest..."
Today's Topics:
1. Re: DVCS at PyCon (Ondrej Certik)
2. Re: using reducing functions without eliminating dimensions?
(Dan Lenski)
3. Re: Another Array (Ian Mallett)
4. Re: Another Array (Robert Kern)
5. Re: Another Array (Ian Mallett)
6. Re: Another Array (Robert Kern)
7. Re: Another Array (Ian Mallett)
8. Re: Another Array (Anne Archibald)
----------------------------------------------------------------------
Message: 1
Date: Thu, 9 Apr 2009 23:14:53 -0700
From: Ondrej Certik <ondrej@certik.cz>
Subject: Re: [Numpy-discussion] DVCS at PyCon
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<85b5c3130904092314o7512cdbfjd2f43b98e65f48cf@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Thu, Apr 9, 2009 at 10:45 PM, David Cournapeau
<david@ar.media.kyoto-u.ac.jp> wrote:
> Ondrej Certik wrote:
>>
>> It is maybe easier to learn how to work with different clones, but
>> once you start working with lots of patches and you need to reclone
>> all the time, then it's the wrong approach to work, as it takes lots
>> of time to copy the whole repository on the disk.
>
> Yes, *I* know how to use git, and I agree with you, I vastly prefer git
> branch handling to bzr branch handling. *I* find working with GUI for
> VCS a real PITA. But I am not the only numpy developer, that's why the
> feedback from people like Josef with a totally different workflow than
> me is valuable - much more than people like us who are unix geeks :)
Yes, definitely.
Ondrej
------------------------------
Message: 2
Date: Fri, 10 Apr 2009 06:36:08 +0000 (UTC)
From: Dan Lenski <dlenski@gmail.com>
Subject: Re: [Numpy-discussion] using reducing functions without
eliminating dimensions?
To: numpy-discussion@scipy.org
Message-ID: <grmpcn$2j4$1@ger.gmane.org>
Content-Type: text/plain; charset=UTF-8
On Thu, 09 Apr 2009 01:31:33 -0500, Robert Kern wrote:
> On Thu, Apr 9, 2009 at 01:29, Anne Archibald <peridot.faceted@gmail.com>
> wrote:
>
>> What's wrong with np.amin(a,axis=-1)[...,np.newaxis]?
>
> It's cumbersome, particularly when you have axis=arbitrary_axis.
Quite right. It would nice to be able to say:
np.amin(a, axiskeep=-1)
or
a.min(axiskeep=3)
... or something along those lines.
Dan
------------------------------
Message: 3
Date: Thu, 9 Apr 2009 23:42:03 -0700
From: Ian Mallett <geometrian@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<a62fab400904092342y5509976bk927277d72730a095@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
It gives a perfect parabolic shape that looks very nice, but somewhat
unrealistic. I'd like to scale the unit vectors by a random length (which
can just be a uniform distribution). I tried scaling the unit vector n*n*3
array by a random n*n array, but that didn't work, obviously. Help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090409/e8fea8
42/attachment-0001.html
------------------------------
Message: 4
Date: Fri, 10 Apr 2009 01:46:47 -0500
From: Robert Kern <robert.kern@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<3d375d730904092346l6850c03chca1962915263e79c@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Fri, Apr 10, 2009 at 01:42, Ian Mallett <geometrian@gmail.com> wrote:
> It gives a perfect parabolic shape that looks very nice, but somewhat
> unrealistic.
Parabolic? They should be spherical.
> I'd like to scale the unit vectors by a random length (which
> can just be a uniform distribution).? I tried scaling the unit vector
n*n*3
> array by a random n*n array, but that didn't work, obviously.
No, it's not obvious. Exactly what code did you try? What results did
you get? What results were you expecting?
> Help?
Let's take a step back. What kind of distribution are you trying to
achieve? You asked for uniformly distributed unit vectors. Now you are
asking for something else, but I'm really not sure what. What standard
are you comparing against when you say that the unit vectors look
"unrealistic"?
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
------------------------------
Message: 5
Date: Thu, 9 Apr 2009 23:58:21 -0700
From: Ian Mallett <geometrian@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<a62fab400904092358m60233289u73aba89a6bdad4b2@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
On Thu, Apr 9, 2009 at 11:46 PM, Robert Kern <robert.kern@gmail.com> wrote:
> Parabolic? They should be spherical.
The particle system in the last screenshot was affected by gravity. In the
absence of gravity, the results should be spherical, yes. All the vectors
are a unit length, which produces a perfectly smooth surface (unrealistic
for such an effect).
> No, it's not obvious. Exactly what code did you try? What results did
> you get? What results were you expecting?
It crashed.
I have this code:
vecs = Numeric.random.standard_normal(size=(self.size[0],self.size[1],3))
magnitudes = Numeric.sqrt((vecs*vecs).sum(axis=-1))
uvecs = vecs / magnitudes[...,Numeric.newaxis]
randlen = Numeric.random.random((self.size[0],self.size[1]))
randuvecs = uvecs*randlen #It crashes here with a dimension mismatch
rgb = ((randvecs+1.0)/2.0)*255.0
I also tried randlen = Numeric.random.random((self.size[0],self.size[1],3)),
but this does not scale each of the vector's components equally, producing
artifacts again. Each needs to be scaled by the same random value for it to
make sense.
> Let's take a step back. What kind of distribution are you trying to
> achieve? You asked for uniformly distributed unit vectors. Now you are
> asking for something else, but I'm really not sure what. What standard
> are you comparing against when you say that the unit vectors look
> "unrealistic"?
The vectors are used to "jitter" each particle's initial speed, so that the
particles go in different directions instead of moving all as one. Using
the unit vector causes the particles to make the smooth parabolic shape.
The jitter vectors much then be of a random length, so that the particles go
in all different directions at all different speeds, instead of just all in
different directions.
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090409/8d6bd9
31/attachment-0001.html
------------------------------
Message: 6
Date: Fri, 10 Apr 2009 02:01:10 -0500
From: Robert Kern <robert.kern@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<3d375d730904100001w4cdb7bedi2b36bca97731ef8c@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Fri, Apr 10, 2009 at 01:58, Ian Mallett <geometrian@gmail.com> wrote:
> On Thu, Apr 9, 2009 at 11:46 PM, Robert Kern <robert.kern@gmail.com>
wrote:
>>
>> Parabolic? They should be spherical.
>
> The particle system in the last screenshot was affected by gravity.? In
the
> absence of gravity, the results should be spherical, yes.? All the vectors
> are a unit length, which produces a perfectly smooth surface (unrealistic
> for such an effect).
>>
>> No, it's not obvious. Exactly what code did you try? What results did
>> you get? What results were you expecting?
>
> It crashed.
> I have this code:
> vecs = Numeric.random.standard_normal(size=(self.size[0],self.size[1],3))
> magnitudes = Numeric.sqrt((vecs*vecs).sum(axis=-1))
> uvecs = vecs / magnitudes[...,Numeric.newaxis]
> randlen = Numeric.random.random((self.size[0],self.size[1]))
> randuvecs = uvecs*randlen #It crashes here with a dimension mismatch
> rgb = ((randvecs+1.0)/2.0)*255.0
>
> I also tried randlen =
Numeric.random.random((self.size[0],self.size[1],3)),
> but this does not scale each of the vector's components equally, producing
> artifacts again.? Each needs to be scaled by the same random value for it
to
> make sense.
See how I did magnitudes[...,numpy.newaxis]? You have to do the same.
>> Let's take a step back. What kind of distribution are you trying to
>> achieve? You asked for uniformly distributed unit vectors. Now you are
>> asking for something else, but I'm really not sure what. What standard
>> are you comparing against when you say that the unit vectors look
>> "unrealistic"?
>
> The vectors are used to "jitter" each particle's initial speed, so that
the
> particles go in different directions instead of moving all as one.? Using
> the unit vector causes the particles to make the smooth parabolic shape.
> The jitter vectors much then be of a random length, so that the particles
go
> in all different directions at all different speeds, instead of just all
in
> different directions.
Ah, okay. That makes sense.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
------------------------------
Message: 7
Date: Fri, 10 Apr 2009 00:07:45 -0700
From: Ian Mallett <geometrian@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<a62fab400904100007y185a80d5jfa4d62a850d1245@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
This seems to work:
vecs = Numeric.random.standard_normal(size=(self.size[0],self.size[1],3))
magnitudes = Numeric.sqrt((vecs*vecs).sum(axis=-1))
uvecs = vecs / magnitudes[...,Numeric.newaxis]
randlen = Numeric.random.random((self.size[0],self.size[1]))
randuvecs = uvecs*randlen[...,Numeric.newaxis]
rgb = ((randuvecs+1.0)/2.0)*255.0
(I have "import numpy as Numeric" for other reasons, that's why there's
Numeric there).
Thanks,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090410/84e6aa
a1/attachment-0001.html
------------------------------
Message: 8
Date: Fri, 10 Apr 2009 03:17:58 -0400
From: Anne Archibald <peridot.faceted@gmail.com>
Subject: Re: [Numpy-discussion] Another Array
To: Discussion of Numerical Python <numpy-discussion@scipy.org>
Message-ID:
<ce557a360904100017l45019b89t32ce233226c4fae0@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
2009/4/10 Ian Mallett <geometrian@gmail.com>:
> The vectors are used to "jitter" each particle's initial speed, so that
the
> particles go in different directions instead of moving all as one.? Using
> the unit vector causes the particles to make the smooth parabolic shape.
> The jitter vectors much then be of a random length, so that the particles
go
> in all different directions at all different speeds, instead of just all
in
> different directions.
Why not just skip the normalization? Then you'll get vectors with
random direction and a natural distribution of lengths. And it'll be
faster than tne unit vectors...
Anne
------------------------------
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
End of Numpy-discussion Digest, Vol 31, Issue 24
************************************************
More information about the Numpy-discussion
mailing list