[Numpy-discussion] Double-ended queues

2012-09-25 Thread William Furnass
Hi all,

I want to be able to within a loop a) apply a mathematical operation
to all elements in a vector (can be done atomically) then b) pop zero
or more elements from one end of the vector and c) push zero or more
elements on to the other end.  So far I've used a collections.deque to
store my vector as it should be more efficient than a numpy array for
the appending and deletion of elements.  However, I was wondering
whether performance could be improved through the use of a
homogeneously-typed double-ended queue i.e. a linked list equivalent
of numpy.ndarray.  Has anyone previously considered whether it would
be worth including such a thing within the numpy package?

Cheers,

Will
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Indexing 2d arrays by column using an integer array

2012-02-13 Thread William Furnass
Hi,

Apologies if the following is a trivial question.  I wish to index the
columns of the following 2D array

In [78]: neighbourhoods
Out[78]:
array([[8, 0, 1],
   [0, 1, 2],
   [1, 2, 3],
   [2, 3, 4],
   [3, 4, 5],
   [4, 5, 6],
   [5, 6, 7],
   [6, 7, 8],
   [7, 8, 0]])

using the integer array

In [76]: perf[neighbourhoods].argmax(axis=1)
Out[76]: array([2, 1, 0, 2, 1, 0, 0, 2, 1])

to produce a 9-element array but can't find a way of applying the
indices to the columns rather than the rows.  Is this do-able without
using loops?

The looped version of what I want is

np.array( [neighbourhoods[i][perf[neighbourhoods].argmax(axis=1)[i]]
for i in xrange(neighbourhoods.shape[0])] )

Regards,

-- 
Will Furnass
Doctoral Student
Pennine Water Group
Department of Civil and Structural Engineering
University of Sheffield

Phone: +44 (0)114 22 25768
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Indexing 2d arrays by column using an integer array

2012-02-13 Thread William Furnass
Thank you, that does the trick.

Regards,

Will

On 13 February 2012 19:39, Travis Oliphant tra...@continuum.io wrote:
 I think the following is what you want:

 neighborhoods[range(9),perf[neighbourhoods].argmax(axis=1)]

 -Travis


 On Feb 13, 2012, at 1:26 PM, William Furnass wrote:

 np.array( [neighbourhoods[i][perf[neighbourhoods].argmax(axis=1)[i]]
 for i in xrange(neighbourhoods.shape[0])] )

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion