> for i in range(m):
> for j in range(n):
> found[i//4,j//4] = cond(x[i,j])
>
Blah, that should be
found[i//4,j//4] |= cond(x[i,j])
Sturla
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
h
On 07.02.2012 15:27, eat wrote:
> This is elegant and very fast as well!
Just be aware that it depends on C ordered input. So:
m,n = data.shape
cond = lamda x : (x >= t1) & (x <= t2)
x = cond(np.ascontiguousarray(data)).reshape((m//4, 4, n//4, 4))
found = np.any(np.any(x, axis=1)
Hi
This is elegant and very fast as well!
On Tue, Feb 7, 2012 at 2:57 PM, Sturla Molden wrote:
> On 06.02.2012 22:27, Sturla Molden wrote:
> >
> >
> >>
> >> # Make a 4D view of this data, such that b[i,j]
> >> # is a 2D block with shape (4,4) (e.g. b[0,0] is
> >> # the same as a[:4, :4]).
> >> b
On 06.02.2012 22:27, Sturla Molden wrote:
>
>
>>
>> # Make a 4D view of this data, such that b[i,j]
>> # is a 2D block with shape (4,4) (e.g. b[0,0] is
>> # the same as a[:4, :4]).
>> b = as_strided(a, shape=(a.shape[0]/4, a.shape[1]/4, 4, 4),
>> strides=(4*a.strides[0], 4*a.strides
Hi,
Sorry for my latest post, hands way too quick ;(
On Mon, Feb 6, 2012 at 9:16 PM, Moroney, Catherine M (388D) <
catherine.m.moro...@jpl.nasa.gov> wrote:
> Hello,
>
> I have to write a code to downsample an array in a specific way, and I am
> hoping that
> somebody can tell me how to do this w
Hi,
On Mon, Feb 6, 2012 at 9:16 PM, Moroney, Catherine M (388D) <
catherine.m.moro...@jpl.nasa.gov> wrote:
> Hello,
>
> I have to write a code to downsample an array in a specific way, and I am
> hoping that
> somebody can tell me how to do this without the nested do-loops. Here is
> the problem
>
> # Make a 4D view of this data, such that b[i,j]
> # is a 2D block with shape (4,4) (e.g. b[0,0] is
> # the same as a[:4, :4]).
> b = as_strided(a, shape=(a.shape[0]/4, a.shape[1]/4, 4, 4),
>strides=(4*a.strides[0], 4*a.strides[1], a.strides[0],
> a.strides[1]))
>
Yes :-) B
The last t1 on each lineis of course t2. Sorry for the typo. Hard to code on an
ipad ;-)
Sturla
Sendt fra min iPad
Den 6. feb. 2012 kl. 22:12 skrev Sturla Molden :
>
> Something like this:
>
> m,n = data.shape
> x = data.reshape((m,n//4,4))
> z = (x[0::4,...] >= t1) & (x[0::4,...] <= t1)
>
Something like this:
m,n = data.shape
x = data.reshape((m,n//4,4))
z = (x[0::4,...] >= t1) & (x[0::4,...] <= t1)
z |= (x[1::4,...] >= t1) & (x[1::4,...] <= t1)
z |= (x[2::4,...] >= t1) & (x[2::4,...] <= t1)
z |= (x[3::4,...] >= t1) & (x[3::4,...] <= t1)
found = np.any(z, axis=2)
Sturla
Sendt f
On Mon, Feb 6, 2012 at 2:57 PM, Sturla Molden wrote:
> Short answer: Create 16 view arrays, each with a stride of 4 in both
> dimensions. Test them against the conditions and combine the tests with an
> |= operator. Thus you replace the nested loop with one that has only 16
> iterations. Or resha
Short answer: Create 16 view arrays, each with a stride of 4 in both
dimensions. Test them against the conditions and combine the tests with an |=
operator. Thus you replace the nested loop with one that has only 16
iterations. Or reshape to 3 dimensions, the last with length 4, and you can do
Hello,
I have to write a code to downsample an array in a specific way, and I am
hoping that
somebody can tell me how to do this without the nested do-loops. Here is the
problem
statement: Segment a (MXN) array into 4x4 squares and set a flag if any of the
pixels
in that 4x4 square meet a cer
12 matches
Mail list logo