Skip to content
jzrake edited this page Feb 19, 2012 · 5 revisions

To create a new numlua array from a Lua table,

local A = lunum.array({1,2,3,4,5})
print(A)

To get a 100-element array of zero-initialized numbers,

local A = lunum.zeros(100)
print(A)

Indexing goes from zero, as in C and Numpy, unlike standard Lua;

A[0] = 1000.0
A[99] = 3.14

Available types are bool, char, short, int, long, float, double, and complex, all part of the lunum namespace. The default data type for arrays is double, but any other may be given as the second argument to array creation functions. Here is an example:

local I = numlua.I
local z = 1.0 + 2.0*I
local A = numlua.zeros(10, lunum.complex)
A[0] = z
print(A)

Clone this wiki locally