Home > Objects -> Lists

EXAMPLES ON MY SAGE PAGE: Sage Lists and NumPy 1d Arrays

Creating Lists
Manipulating Lists - Commands on Lists
Manipulating Lists - Operations with Lists

In Sage

  • A list is an ordered collection of objects. The objects do not have to be the same type. (A 1D array is also a list, but all the objects must have the same type.)
  • A list is often called a sequence. It is 1-dimensional. Its elements are separated by commas.
  • The elements of a list are indexed by the integers, starting with 0.

When doing numerical math, lists should only be used for classroom. NumPy (numeric python) arrays should be used in real life.

  • A Sage list of numbers is automatically converted to float64 (decimals); not so with NumPy arrays
  • Within an operation, Sage will use a list either as row matrix or a column matrix depending on what works. This is REALLY handy.

Important: Sage lists and NumPy 1D array have similarities AND differences

The MAIN difference is that a Sage list is more easily manipulated and a NumPy 1D array is faster for calculations.

References: http://www-rohan.sdsu.edu/~mosulliv/sagetutorial/sageprog.html

Keywords: sage, lists, sequences, elements, numpy, array