1 | initial version |
Here is a one liner that might be a bit better since the numpy function tolist is optimized:
sage: sum((m[i,i+1:].tolist() for i in range(4)), [])
[1, 2, 3, 6, 7, 11]
Vincent
2 | No.2 Revision |
Here is a one liner that might be a bit better since the numpy function tolist is optimized:
sage: sum((m[i,i+1:].tolist() for i in range(4)), [])
[1, 2, 3, 6, 7, 11]
And if you want to be smarter with respect to memory allocation you can do
sage: l = []
sage: for i in range(4):
....: l.extend(m[i,i+1:].tolist())
sage: l
[1, 2, 3, 6, 7, 11]
Vincent
3 | No.3 Revision |
Here is a one liner that might be a bit better since the numpy function tolist is optimized:
sage: sum((m[i,i+1:].tolist() for i in range(4)), [])
[1, 2, 3, 6, 7, 11]
And if you want to be smarter with respect to memory allocation you can do
sage: l = []
sage: for i in range(4):
....: l.extend(m[i,i+1:].tolist())
sage: l
[1, 2, 3, 6, 7, 11]
Vincent