List reference at offset

C

Colin.Hankins

Disclaimer: I'm learning python and would like to use it in a
project.

The project will have many large matricies. In one particular instance
I need to reference a smaller submatrix of the larger matrix. I don't
want to create a new copy or even change any of the values, I just
want to quickly and easily be able to look at this sub matrix.

So I am using lists of lists for the matricies (I am also playing with
NumPy) and is there anyway to create a pointer to an offset in a
list?

I know you can have A = B = [] which would be the same.

And I know I can simply do a B[x + offset to submatrix].

But I was hoping there may be a way to just have a pointer? Or is
there another more efficient method to do this in python?

Thanks!
 
P

Peter Otten

Disclaimer: I'm learning python and would like to use it in a
project.

The project will have many large matricies. In one particular instance
I need to reference a smaller submatrix of the larger matrix. I don't
want to create a new copy or even change any of the values, I just
want to quickly and easily be able to look at this sub matrix.

So I am using lists of lists for the matricies (I am also playing with
NumPy) and is there anyway to create a pointer to an offset in a
list?

I know you can have A = B = [] which would be the same.

And I know I can simply do a B[x + offset to submatrix].

But I was hoping there may be a way to just have a pointer? Or is
there another more efficient method to do this in python?

What you describe is what numpy does:

"""
Therefore, a regular indexing expression on an ndarray can always produce an
ndarray object without copying any data. This is sometimes referred to as
the “view†feature of array indexing, and one can see that it is enabled by
the use of striding information in the underlying ndarray object. The
greatest beneï¬t of this feature is that it allows indexing to be done
very rapidly and without exploding memory usage (because no copies of the
data are made).
"""
 
C

Colin.Hankins

Disclaimer: I'm learning python and would like to use it in a
project.
The project will have many large matricies. In one particular instance
I need to reference a smaller submatrix of the larger matrix. I don't
want to create a new copy or even change any of the values, I just
want to quickly and easily be able to look at this sub matrix.
So I am using lists of lists for the matricies (I am also playing with
NumPy) and is there anyway to create a pointer to an offset in a
list?
I know you can have A = B = [] which would be the same.
And I know I can simply do a B[x + offset to submatrix].
But I was hoping there may be a way to just have a pointer? Or is
there another more efficient method to do this in python?

What you describe is what numpy does:

"""
Therefore, a regular indexing expression on an ndarray can always produce an
ndarray object without copying any data. This is sometimes referred to as
the “view†feature of array indexing, and one can see that it is enabled by
the use of striding information in the underlying ndarray object. The
greatest beneï¬t of this feature is that it allows indexing to be done
very rapidly and without exploding memory usage (because no copies of the
data are made).
"""- Hide quoted text -

- Show quoted text -

Thank you. That certainly did the trick!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,291
Messages
2,571,455
Members
48,132
Latest member
KatlynC08

Latest Threads

Top