Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Matrix indexing standard

Hello, Sage Community!

Since I learned Sage, I have used the notation A[i][j] (which obviously came from my previous experience with Python lists) to access the (i+1, j+1)-th element of a matrix. However, I discovered a few weeks ago that I can also use the syntax A[i,j]. I am wondering which of these two ways of matrix indexing is preferred in Sage?

My tests using timeit indicate that the second syntax is faster than the first one by a factor of 500. So I suppose it to be simply natural that the fastest syntax is preferred. However, why to deviate from the list syntax? After all, lists and lists of lists are (in some sense) arrays, too.

Thanks in advance for your answers!

Matrix indexing standard

Hello, Sage Community!

Since I learned Sage, I have used the notation A[i][j] (which obviously came from my previous experience with Python lists) to access the (i+1, j+1)-th element of a matrix. However, I discovered a few weeks ago that I can also use the syntax A[i,j]. I am wondering which of these two ways of matrix indexing is preferred in Sage?

My tests using timeit indicate that the second syntax is faster than the first one by a factor of 500. So I suppose it to be simply natural that the fastest syntax is preferred. However, why to deviate from the list syntax? After all, lists and lists of lists are (in some sense) arrays, too.

Thanks in advance for your answers!

Matrix indexing standardand list standards

Hello, Sage Community!

Since I learned Sage, I have used the notation A[i][j] (which obviously came from my previous experience with Python lists) to access the (i+1, j+1)-th element of a matrix. However, I discovered a few weeks ago that I can also use the syntax A[i,j]. I am wondering which of these two ways of matrix indexing is preferred in Sage?

My tests using timeit indicate that the second syntax is faster than the first one by a factor of 500. So I suppose it to be simply natural that the fastest syntax is preferred. However, why to deviate from the list syntax? After all, lists and lists of lists are (in some sense) arrays, too.

On the other hand, talking about lists, there is the syntax [1..10], which creates the list

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Why is this the case when Python would ignore the 10? For example, range(1, 10) is equivalent to

[1, 2, 3, 4, 5, 6, 7, 8, 9]

and srange(1, 10) creates the same list, but with Sage Integers, instead of Python's ints. Is there any good reason for having [1..10]be equivalent to srange(1, 11)?

Thanks in advance for your answers!

Matrix indexing and list standards

Hello, Sage Community!

Since I learned Sage, I have used the notation A[i][j] (which obviously came from my previous experience with Python lists) to access the (i+1, j+1)-th element of a matrix. However, I discovered a few weeks ago that I can also use the syntax A[i,j]. I am wondering which of these two ways of matrix indexing is preferred in Sage?

My tests using timeit indicate that the second syntax is faster than the first one by a factor of 500. So I suppose it to be simply natural that the fastest syntax is preferred. However, why to deviate from the list syntax? After all, lists and lists of lists are (in some sense) arrays, too.

On the other hand, talking about lists, there is the syntax [1..10], which creates the list

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Why is this the case when Python would ignore the 10? For example, range(1, 10) is equivalent to

[1, 2, 3, 4, 5, 6, 7, 8, 9]

and srange(1, 10) creates the same list, but with Sage Integers, instead of Python's ints. Is there any good reason for having [1..10]be equivalent to srange(1, 11)?

Thanks in advance for your answers!

[Sage vs Python] Matrix indexing and list standards

Hello, Sage Community!

Since I learned Sage, I have used the notation A[i][j] (which obviously came from my previous experience with Python lists) to access the (i+1, j+1)-th element of a matrix. However, I discovered a few weeks ago that I can also use the syntax A[i,j]. I am wondering which of these two ways of matrix indexing is preferred in Sage?

My tests using timeit indicate that the second syntax is faster than the first one by a factor of 500. So I suppose it to be simply natural that the fastest syntax is preferred. However, why to deviate from the list syntax? After all, lists and lists of lists are (in some sense) arrays, too.

On the other hand, talking about lists, there is the syntax [1..10], which creates the list

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Why is this the case when Python would ignore the 10? For example, range(1, 10) is equivalent to

[1, 2, 3, 4, 5, 6, 7, 8, 9]

and Even srange(1, 10) creates the same list, but with Sage Integers, instead of Python's ints. Is there any good reason for having [1..10]be equivalent to srange(1, 11)?

Thanks in advance for your answers!