ndarray

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package ndarray is a require()-able host module providing a dense, N-dimensional numeric array — the NumPy-style primitive that most data-science numerics build on. Unlike a Lua table (a boxed hash map), an ndarray stores its elements in a single contiguous []float64 in row-major (C) order, so vectorized arithmetic, reductions, and matrix products run over flat Go slices instead of chasing pointers.

Construction:

local nd = require("ndarray")
a = nd.array({ {1, 2, 3}, {4, 5, 6} })   -- 2x3 from nested tables
z = nd.zeros(2, 3)                        -- 2x3 of zeros
r = nd.arange(0, 10)                      -- 0,1,..,9  (1-D)
l = nd.linspace(0, 1, 5)                  -- 5 points in [0,1]
i = nd.eye(3)                             -- 3x3 identity

Arithmetic operators are overloaded and broadcast NumPy-style, so an array and a scalar, or two arrays whose shapes align, combine elementwise:

b = a * 2 + 1
c = a + nd.array({10, 20, 30})           -- row broadcast over a 2x3

Reductions take an optional axis; with no axis they collapse to a scalar:

a:sum()          -- scalar
a:mean(1)        -- per-row means (a 1-D array of length 2)

Every arithmetic/transform method returns a NEW array; the receiver is never mutated (only :set and the in-place-free API mutate, explicitly).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterNDArrayPreload

func RegisterNDArrayPreload(v *vm.VM)

RegisterNDArrayPreload installs the loader under package.preload.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL