Lua学习笔记

1.教程
  教程博客分为1-4,主要讲lua特性和与其他已经熟悉的语言区别之处。

  http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/

  手册:http://www.lua.org/manual/5.2/

  FAQ:http://www.luafaq.org/

  

2、学习

很重要的一点, 索引从1开始。

2.1 Before using it, it's a good idea to set the seed with math.randomseed. A common thing to do is math.randomseed(os.time()).

2.2 or 操作符,有点类似于 C里的 a > b ? a : b;

or可以用来检查是否空: y = y or 0;

if y == nil then y = 0 end

2.3 函数的参数是table时,调用时可以省略小括号。

2.4 变参数

function fun(...)

有点像模板类。

2.5 select函数

select("#", ...);

select(i , ...)

"#"返回每个pairs的长度

2.6 pairs 和 ipairs

pairs return key and value;

ipairs return indice and value, start at 1.

2.7 self 和 : 与. 的 一个例子

  

  2.8 Tensor的操作

    http://jucor.github.io/torch-doc-template/tensor.html

    (1)[Tensor] repeatTensor

    torch.repeatTensor

  

    (2)max

    torch.max(a, n)

     参数n是返回时的dimension,对于二维的,如果n是1则返回一行,n是2则返回一列;

 

     

 

   

 

posted @ 2017-10-27 09:17  赵小春  阅读(248)  评论(0编辑  收藏  举报