[Numpy-discussion] Array views

srean srean.list at gmail.com
Sat Mar 26 13:32:24 EDT 2011


 I am also interested in this. In my application there is a large 2d array,
lets call it 'b' to keep the notation consistent in the thread.  b's
columns need to be recomputed often. Ideally this re-computation happens in
a function. Lets call that function updater(b, col_index): The simplest
example is where
updater(b, col_index) is a matrix vector multiply, where the matrix or the
vector changes.

 Is there anyway apart from using ufuncs that I can make updater() write the
result directly in b and not create a new temporary column that is then
copied into b ?  Say for the matrix vector multiply example.
I can write the matrix vector product in terms of ufuncs but will lose out
in terms of speed.

In the best case scenario I would like to maintain 'b' in a csr sparse
matrix form, as 'b' participates in a matrix vector multiply. I think csr
would be asking for too much, but even ccs should help.  I dont want to
clutter this thread with the sparsity issues though, any solution to the
original question or pointers to solutions would be appreciated.


On Sat, Mar 26, 2011 at 12:10 PM, Hugo Gagnon <
sourceforge.numpy at user.fastmail.fm> wrote:

> Hello,
> Say I have a few 1d arrays and one 2d array which columns I want to be
> the 1d arrays.
> I also want all the a's arrays to share the *same data* with the b
> array.
> If I call my 1d arrays a1, a2, etc. and my 2d array b, then
> b[:,0] = a1[:]
> b[:,1] = a2[:]
> ...
> won't work because apparently copying occurs.
> I tried it the other way around i.e.
> a1 = b[:,0]
> a2 = b[:,1]
> ...
> and it works but that doesn't help me for my problem.
> Is there a way to reformulate the first code snippet above but with
> shallow copying?
> Thanks,
> --
>  Hugo Gagnon
> --
>  Hugo Gagnon
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110326/bbe27581/attachment.html>

More information about the NumPy-Discussion mailing list