>>from Numeric import zeros
>>p=zeros(3) p
array([0,0,0])
>>p[0]
0
>>x=p[0] x=10 p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior
I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please? 2 1163 du*********@gmail.com wrote:
>>>from Numeric import zeros p=zeros(3) p
array([0,0,0])
>>>p[0]
0
>>>x=p[0] x=10 p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior
I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please?
Nope, python can't do this.
Diez du*********@gmail.com wrote:
>from Numeric import zeros p=zeros(3) p
array([0,0,0])
>p[0]
0
>x=p[0]
`x' is now a reference to immutable integer object
with value 0, not to first element of array `p'
>x=10
now `x' is a reference to immutable integer object
with value 10, array doesn't change
>p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior
I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class. i dont want accessor methods. i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading. a little help please?
You can have such a reference to mutable objects.
Consider this:
>>p = [[0,0,0], [0,0,0]] x = p[0] # reference to mutable list object x[0] = 10 p
[[10, 0, 0], [0, 0, 0]]
--
HTH,
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christian Seberino |
last post by:
How does Ruby compare to Python?? How good is DESIGN of Ruby compared to Python?
Python's design is godly. I'm wondering if Ruby's is godly too.
I've heard it has solid OOP design but then...
|
by: Shufen |
last post by:
Hi all,
Can someone who has use PHP before and know quite well about the
language, tell me what are the stuffs that Python offers and PHP
doesn't. A few examples will be nice. I know about the...
|
by: Michael Tobis |
last post by:
Someone asked me to write a brief essay regarding the value-add
proposition for Python in the Fortran community. Slightly modified to
remove a few climatology-related specifics, here it is.
I...
|
by: diffuser78 |
last post by:
I have a python code which is running on a huge data set. After
starting the program the computer becomes unstable and gets very
diffucult to even open konsole to kill that process. What I am...
|
by: skip |
last post by:
After much wailing and gnashing of teeth the past couple of days, I managed
to move (most of?) the content from the MacPython wiki to the main Python
wiki (*). All pages were created as subpages...
|
by: vishnu |
last post by:
Hi there,
I am embedding python 2.5 on embedded system running on RTOS where I
had strict memory constraints.
As python is a huge malloc intensive application, I observed huge
memory...
|
by: none |
last post by:
Hello,
IIRC, I once saw an explanation how Python doesn't have "variables" in
the sense that, say, C does, and instead has bindings from names to
objects. Does anyone have a link?
Thanks,
...
|
by: Santiago Romero |
last post by:
Is there a way to check the REAL size in memory of a python object?
Something like
or
or something like that ...
|
by: Palindrom |
last post by:
Hi everyone !
I'd like to apologize in advance for my bad english, it's not my
mother tongue...
My girlfriend (who is a newbie in Python, but knows Perl quite well)
asked me this morning why...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |