Dense vectors using a NumPy backend.#

AUTHORS:

  • Jason Grout, Oct 2008: switch to numpy backend, factored out Vector_double_dense class

  • Josh Kantor

  • William Stein

class sage.modules.vector_numpy_dense.Vector_numpy_dense#

Bases: FreeModuleElement

Base class for vectors implemented using numpy arrays.

This class cannot be instantiated on its own. The numpy vector creation depends on several variables that are set in the subclasses.

EXAMPLES:

sage: v = vector(RDF, [1,2,3,4]); v
(1.0, 2.0, 3.0, 4.0)
sage: v*v
30.0
numpy(dtype=None)#

Return numpy array corresponding to this vector.

INPUT:

  • dtype – if specified, the numpy dtype

    of the returned array.

EXAMPLES:

sage: v = vector(CDF,4,range(4))
sage: v.numpy()
array([0.+0.j, 1.+0.j, 2.+0.j, 3.+0.j])
sage: v = vector(CDF,0)
sage: v.numpy()
array([], dtype=complex128)
sage: v = vector(RDF,4,range(4))
sage: v.numpy()
array([0., 1., 2., 3.])
sage: v = vector(RDF,0)
sage: v.numpy()
array([], dtype=float64)

A numpy dtype may be requested manually:

sage: import numpy
sage: v = vector(CDF, 3, range(3))
sage: v.numpy()
array([0.+0.j, 1.+0.j, 2.+0.j])
sage: v.numpy(dtype=numpy.float64)
array([0., 1., 2.])
sage: v.numpy(dtype=numpy.float32)
array([0., 1., 2.], dtype=float32)