Hello,
I am trying to solve a simple problem that becomes complex if I try to
avoid looping.
Let's say I have a 1D array, x, where x[i] = x[i+1]
Given a certain value delta, I would like to get a subset of x, named y,
where (y[i+1] - y[i]) = delta
In a non-optimized and trivial way, the
Well, this seems to be quite close to what I need
y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
i1 = numpy.nonzero(y[1:] y[:-1])
y = numpy.take(x, i1)
Sorry for the time taken!
Best regards,
Armando
V. Armando Solé wrote:
Hello,
I am trying to solve a simple problem that
There might be an easier way to accomplish that
y = x[(x[1:]-x[:-1]) = delta]
cheers
Am Mittwoch, den 09.06.2010, 10:00 +0200 schrieb V. Armando Solé:
Well, this seems to be quite close to what I need
y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
i1 = numpy.nonzero(y[1:]
A Wednesday 09 June 2010 10:00:50 V. Armando Solé escrigué:
Well, this seems to be quite close to what I need
y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
i1 = numpy.nonzero(y[1:] y[:-1])
y = numpy.take(x, i1)
Perhaps this is a bit shorter:
y = x[(x[1:] - x[:-1]) = delta]
--
Hah beat you to it one minute ;)
Am Mittwoch, den 09.06.2010, 10:08 +0200 schrieb Francesc Alted:
A Wednesday 09 June 2010 10:00:50 V. Armando Solé escrigué:
Well, this seems to be quite close to what I need
y = numpy.cumsum((x[1:]-x[:-1])/delta).astype(numpy.int)
i1 =
That was my first thought, but that only warrants me to skip one point
in x but not more than one.
x= numpy.arange(10.)
delta = 3
print x[(x[1:] - x[:-1]) = delta]
[]
instead of the requested [0, 4, 8]
Armando
Francesc Alted wrote:
A Wednesday 09 June 2010 10:00:50 V. Armando Solé
Yeah, damn you! ;-)
A Wednesday 09 June 2010 10:11:33 Robert Elsner escrigué:
Hah beat you to it one minute ;)
Am Mittwoch, den 09.06.2010, 10:08 +0200 schrieb Francesc Alted:
A Wednesday 09 June 2010 10:00:50 V. Armando Solé escrigué:
Well, this seems to be quite close to what I need
Francesc Alted wrote:
Yeah, damn you! ;-)
I think you still have room for improvement ;-)
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
A Wednesday 09 June 2010 10:14:22 V. Armando Solé escrigué:
That was my first thought, but that only warrants me to skip one point
in x but not more than one.
x= numpy.arange(10.)
delta = 3
print x[(x[1:] - x[:-1]) = delta]
[]
instead of the requested [0, 4, 8]
True! Wanting
Given a certain value delta, I would like to get a subset of x, named
y,
where (y[i+1] - y[i]) = delta
So in fact the problem is to find y such that
(y[i(k)+n] - y[i(k)]) = delta
for n = len(x) - 1 - i
and i(0) = 0, i(k+1) = i(k) + n
? Well a loop or list comparison seems like a good
Well happens. The problem description was not 100% clear thus I still
think your line did solve the problem. A simple misunderstanding. So
what do I learn from it?: Always look at the code, not the
description :D
Am Mittwoch, den 09.06.2010, 10:19 +0200 schrieb Francesc Alted:
A Wednesday 09
On Wed, Jun 9, 2010 at 4:16 PM, Francesc Alted fal...@pytables.org wrote:
A Tuesday 08 June 2010 23:34:09 Anne Archibald escrigué:
But the issue isn't one of efficiency, it's merely an arbitrarily chosen
convention. (Does anyone know the history of the choices for FORTRAN and
C, esp. why
Hi,
I'm reading netCDF files using pupynere and I want to extract 22
values from a 1440x400 array. I have the indices of the values, they
are:
92 832
92 833
91 832
91 833
91 834
90 835
90 832
90 833
90 834
89 832
89 833
89 834
88
On 9 June 2010 12:01, Hanlie Pretorius hanlie.pretor...@gmail.com wrote:
I'm reading netCDF files using pupynere and I want to extract 22
values from a 1440x400 array. I have the indices of the values, they
are:
92 832
92 833
91 832
91 833
...
What is the best way to
/
/ Given a certain value delta, I would like to get a subset of x, named
// y,
// where (y[i+1] - y[i])= delta
/
So in fact the problem is to find y such that
(y[i(k)+n] - y[i(k)])= delta
for n= len(x) - 1 - i
and i(0) = 0, i(k+1) = i(k) + n
? Well a loop or list comparison seems like a
I suspect the author meant that instead (or a simple minus in front of
the delta). Just posting because I wondered the same this morning after
looking at it (after the first misunderstanding).
It looks much better to me than the cumsum approach with its hidden test
for true using
Correct. I thought just multiplying by -1 and inverting the logical
condition would give me the same output.
This makes exactly what I want:
x= numpy.arange(10.)
delta=3
y=[x[0]]
for value in x:
... if (value-y[-1]) delta:
...y.append(value)
...
y
[0., 4., 8.]
Armando
I think that arrays are just syntax on pointer is indeed the key
reason for how C works here. Since a[b] really means a + b (which is
why 5[a] and a[5] are the same), I don't see how to do it differently.
Holy crap! You can do that in C?!
___
On Wed, Jun 9, 2010 at 02:19, Pierre GM pgmdevl...@gmail.com wrote:
On Jun 8, 2010, at 4:37 AM, Sebastian Haase wrote:
another note:
http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#arrays-indexing-rec
should not say record array - because recarray a special in that
they can
? Well a loop or list comparison seems like a good choice to me. It is
much more obvious at the expense of two LOCs. Did you profile the two
possibilities and are they actually performance-critical?
cheers
The second is between 8 and ten times faster on my machine.
import numpy
import
It gets even worse with data similar to those I will be using.
With:
x0 = numpy.linspace(-1,1, 1)
niter = 2000
I get 24 seconds for option1 and 0.64 seconds for option2.
Considering I expect between 5 and 50 times that number of iterations,
the difference is already quite considerable.
On Wed, Jun 9, 2010 at 11:31 AM, Vicente Sole s...@esrf.fr wrote:
It gets even worse with data similar to those I will be using.
With:
x0 = numpy.linspace(-1,1, 1)
niter = 2000
I get 24 seconds for option1 and 0.64 seconds for option2.
Considering I expect between 5 and 50 times that
Quoting josef.p...@gmail.com:
but the two options don't produce the same result in general, the
cumsum version doesn't restart from zero, I think
try
x0 = np.random.randint(5,size=30).cumsum()
with delta=3
I don't see a way around recursive looping
The x0 data are already sorted. It was
On Wed, Jun 9, 2010 at 11:47 AM, Vicente Sole s...@esrf.fr wrote:
Quoting josef.p...@gmail.com:
but the two options don't produce the same result in general, the
cumsum version doesn't restart from zero, I think
try
x0 = np.random.randint(5,size=30).cumsum()
with delta=3
I don't see a
On Thu, Jun 10, 2010 at 12:09 AM, Benjamin Root ben.r...@ou.edu wrote:
I think that arrays are just syntax on pointer is indeed the key
reason for how C works here. Since a[b] really means a + b (which is
why 5[a] and a[5] are the same), I don't see how to do it differently.
Holy crap! You
On Wed, Jun 9, 2010 at 9:00 AM, David Cournapeau courn...@gmail.com wrote:
On Thu, Jun 10, 2010 at 12:09 AM, Benjamin Root ben.r...@ou.edu wrote:
I think that arrays are just syntax on pointer is indeed the key
reason for how C works here. Since a[b] really means a + b (which is
why 5[a]
Hi Josef,
I do not need regular spacing of the original data. I only need them to
be sorted and that I get it with a previous numpy call. Then the
algorithm using the cumsum does the trick without a explicit loop.
Armando
___
NumPy-Discussion
When I run
import numpy as np
a = np.ones((400, 50), dtype=np.float32)
c = np.dot(a, a.T)
produces a MemoryError on the 32-bit Enthought Python Distribution
on 32-bit Vista. I understand this has to do with the 2GB limit with
32-bit python and the fact numpy wants a contiguous chunk of
greg whittier wrote:
When I run
import numpy as np
a = np.ones((400, 50), dtype=np.float32)
c = np.dot(a, a.T)
produces a MemoryError on the 32-bit Enthought Python Distribution
on 32-bit Vista. I understand this has to do with the 2GB limit with
32-bit python and the fact numpy
On Wed, Jun 9, 2010 at 12:57 PM, V. Armando Solé s...@esrf.fr wrote:
greg whittier wrote:
a = np.ones((400, 50), dtype=np.float32)
c = np.dot(a, a.T)
In such cases I create a matrix of zeros with the final size and I fill
it with a loop of dot products of smaller chunks of the original
On 6/9/2010 12:49 PM, greg whittier wrote:
Is there a way to do A*A.T without two
copies of A?
Does this do what you want?
Alan Isaac
a
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
np.tensordot(a,a,axes=(-1,-1))
array([[ 1, 3, 5, 7, 9],
[
Alan G Isaac wrote:
On 6/9/2010 12:49 PM, greg whittier wrote:
Is there a way to do A*A.T without two
copies of A?
Does this do what you want?
Alan Isaac
a
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
On Wed, Jun 9, 2010 at 1:16 PM, Alan G Isaac ais...@american.edu wrote:
On 6/9/2010 12:49 PM, greg whittier wrote:
Is there a way to do A*A.T without two
copies of A?
Does this do what you want?
Alan Isaac
np.tensordot(a,a,axes=(-1,-1))
This seems to suffer from the same problem. A
Dear all,
We've been having discussions on the pystatsmodels mailing list
recently regarding data structures and other tools for statistics /
other related data analysis applications. I believe we're trying to
answer a number of different, but related questions:
1. What are the sets of
On 06/09/2010 10:24 AM, Vicente Sole wrote:
? Well a loop or list comparison seems like a good choice to me. It is
much more obvious at the expense of two LOCs. Did you profile the two
possibilities and are they actually performance-critical?
cheers
The second is between 8 and ten
Hi everyone,
This is a follow-up to Travis's message on the re-factoring project from May
25th and the subsequent discussion. For background, I am a developer at
Enthought working on the NumPy re-factoring project with Travis and Scott.
The immediate goal from our perspective is to re-factor the
Dear All ..
I tried to install numpy and scipy ... basicaly I want to use OMPC
I Installed SuiteSparse :
---START---
b...@bino:~/mydoc/buku/arduino/scipy/scipy-0.8.0b1$ ls -l
/usr/local/lib/lib*a
-rw-r--r-- 1 root root 51860 2010-06-10 10:59
/usr/local/lib/libamd.2.2.1.a
lrwxrwxrwx 1 root
37 matches
Mail list logo