Ask Your Question

Revision history [back]

Responding to @Mathmon's comment to @kcrisman's first (?) answer: that's because "v" is a reference (pointer) to a vector object somewhere in memory. The statement v = copy(w) creates a new vector in memory with a copy of ws content and then assigns v as a reference to that new vector.

In the dictionary, I[1] is another reference (to the location in memory of the value associated with the key 1. So, for example if you want to update the vector value in I you could do something like:

sage: I = { 1: vector(QQ, (1,2)) }
sage: a = I[1]
sage: a.set(0,3)
sage: I
{1: (3, 2)}

to reassign the reference I[1] use it's name (not a secondary reference to the same location):

sage: w = vector(QQ, (4,5))
sage: I[1] = copy(w)
sage: I
{1: (4, 5)}