Skip to content

ToNDArray

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

ToNDArray[list] returns list stored as a dense machine-precision buffer. The result is still a List -- same Head, same printed form, same elements -- but NDArrayQ gives True for it. ToNDArray[list, DataType -> "float64"] forces the element type. Returns list unchanged when it is not rectangular, is empty, or holds anything other than uniformly Integer or uniformly Real machine values. Unlike automatic packing it ignores the size threshold.

Examples (5)

Every input below was run against the current Mathilda build and its output recorded.

Scope (3)

In[1]:= DataType[ToNDArray[{True, False, True}]]
Out[1]= "bool"

A numeric buffer -> a bool one

In[2]:= Positive[ToNDArray[{-1, 0, 2}]]
Out[2]= {False, False, True}

Not numeric: delists to symbolic

In[3]:= Sin[ToNDArray[{True, False}]]
Out[3]= {Sin[True], Sin[False]}

Options (2)

In[4]:= DataType[ToNDArray[{1, 2, 3}, DataType -> "float64"]]
Out[4]= "float64"

In[5]:= NDArrayQ[ToNDArray[{1., 2.5}, DataType -> "int64"]]
Out[5]= False

Implementation notes

Attributes: Protected.

References

See also: Rational, Complex, DataType, List