Up to date

This page is up to date for NumDot stable. If you still find outdated information, please open an issue.

NumPy, xtensor, and NumDot

NumDot attempts to recreate NumPy-like behavior, and uses xtensor under the hood. While most things are consistent across all three libraries, differences exist.

Fundamental Comparison

  • NumDot functions always return tensors, to avoid accidentally promoting dtypes. NumPy returned types like np.float32 can be used like primitive numbers.

  • NumDot does not overload operators like + and *, due to a gdscript limitation.

  • NumDot does not support subscripts (a[start:stop:step], due to a gdscript limitation. Instead, use a.get(nd.range(start, stop, step).

  • NumPy supports keyword arguments. NumDot only supports ordered arguments, due to a gdscript limitation.

  • xtensor operations are lazy views. NumPy and NumDot operations evaluate immediately, with the exception of strideable views.

Function Cheat Sheet

NumPy, xtensor and NumDot Cheat Sheet

NumPy

xtensor

NumDot

Notes

a.shape

a.shape()

a.shape()

a.size

a.size()

a.size()

a.ndim

a.dimension()

a.ndim()

a[0]

xt::view(a, { 0 })
a(0)
a.get(0)
a.get_int(0)
a.get_float(0)

Create a view, or return an element of the tensor.

a[0] = b

xt::view(a, { 0 }) = b
a(0) = b
a.set(b, 0)

Update a slice of a tensor.

a[:]

xt::view(a, { xt::all() })

a.get(&":")

Select all elements.

a[None]

xt::view(a, { xt::newaxis() })

a.get(&"newaxis"), a.get(null)

Insert new axis.

a[..., 0]

xt::view(a, { xt::ellipsis(), 0 })

a.get(&"...", 0)

Ellipsis stands in for all other dimensions.

a[2:]

xt::view(a, { 2|_ })

a.get(nd.from(2))

Select elements starting at index 2.

a[:2]

xt::view(a, { _|2 })

a.get(nd.to(2))

Select elements ending at index 2.

a[2:4]

xt::view(a, { 2|4 })

a.get(nd.range(2, 4))

Select elements starting at index 2, ending at index 4.

a[2:40:2]

xt::view(a, { 2|40|2 })

a.get(nd.range(2, 40, 2))

Select every second element, starting at index 2, ending at index 4.

a + b
np.add(a, b)

a + b

nd.add(a, b)

a - b
np.subtract(a, b)

a - b

nd.subtract(a, b)

a * b
np.multiply(a, b)

a * b

nd.multiply(a, b)

a / b
np.divide(a, b)

a / b

nd.divide(a, b)

np.sin(a)

xt::sin(a)

nd.sin(a)

Analogous for all trig functions.

np.degrees
np.deg2rad

xt::deg2rad

nd.deg2rad

np.radians
np.rad2deg

xt::rad2deg

nd.rad2deg

Haven't found what you need? Try nd!


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.