You can declare multi-line functions using the Notebook or the qtconsole with ctrl+intro.
In [1]:
function fib(n)
if n <= 2 then return 1 end
return fib(n-1) + fib(n-2)
end
In [2]:
for i=1,10 do print("fib("..i..") =",fib(i)) end
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
Out[2]:
It is possible to declare tables as usual.
In [3]:
tbl = {
a = 1,
b = 2,
"Hello", "World", "!"
}
And the table can be shown as usual or using the fancy show() command.
In [4]:
print(tbl)
show(tbl)
Out[4]:
Out[4]:
You can even show multiple objects by columns because show() accepts a variable number of arguments.
In [5]:
show(tbl, {1,2,3,4})
Out[5]:
The function vars() allow shows all the variables declared by the user (global variables).
In [6]:
vars()
Out[6]:
APRIL-ANN, a toolkit for pattern recognition tasks, has been connected with IPyLua and it is possible to show matrices, images and plots.
In [7]:
require "aprilann"
x = matrix(300,300):linspace(0,0.5)
x = x + x:t()
x_img = Image(x)
show(x_img, x)
Out[7]:
Finally, it is possible to perform basic plots (currently: points, bars, lines, hist2d). Plots receive several series, which can be plain Lua tables (with numeric indices or array tables) or APRIL-ANN matrices.
In [10]:
local x = matrix(120,1):linspace(-10,10)
local y = stats.dist.normal(0,2):logpdf(x):exp()
local fig = bokeh.figure{ width=600, height=500 }
-- bars using Lua arrays
fig:bars{ x=0, y=0.1, height=0.2, width=2, alpha=0.3 }
-- bars with APRIL-ANN matrix
fig:bars{ x=x, height=y, y = y/2, width=0.01, color=fig:color_num(1), alpha=0.3 }
-- lines with APRIL-ANN matrix
fig:lines{ x=x, y=y, width=3, color=fig:color_num(1), alpha=0.3, legend="Normal" }
-- points with APRIL-ANN matrix
fig:points{ x=x, y=y, color=fig:color_num(1) }
show(fig)
Out[10]: