The elements of a vector can be manipulated like the elements of any other Python sequence type, such as lists and strings. That means individual elements are accessed using square brackets, as shown in the following example:
u = vector(QQ, [1, 2/7, 10/3]) # QQ is the field of rational numbers print("u=" + str(u)) print("Elements: {0}, {1}, {2}".format(u[0], u[1], u[2])) print("The slice [0:2] is {0}".format(u[0:2])) print("The last element is {0}".format(u[-1])) u[len(u) - 1] = 3/2 print("The last element is now {0}".format(u[-1])) print "Assigning a real value to an element:" u[2] = numerical_approx(pi, digits=5) print(u)
The output from this code will look like this if you are using the notebook interface: