mxnet系列3-hello,mxnet
mxnet的helloword程序
mxnet的是用c++写成的,但基于mxnet的编程可以使用各种语言接口,这里老衲使用python作为接口
环境的准备如下
wget https://bootstrap.pypa.io/get-pip.py && sudo python get-pip.py
sudo pip install mxnet //安装mxnet-cpu
pip install mxnet-cu80 //安装mxnet-cuda8.0
mxnet提供了定义多维数组的接口
>>> import mxnet as mx >>> a = mx.nd.ones((2, 3)) >>> b = a * 2 + 1 >>> b.asnumpy() # print b by converting to a numpy.ndarray object array([[ 3., 3., 3.], [ 3., 3., 3.]], dtype=float32)
和numpy和matlab类似
mxnet支持符号式编程,编程的结果是形成了一张图
import mxnet as mx a = mx.sym.Variable("A") # represent a placeholder. These can be inputs, weights, or anything else. b = mx.sym.Variable("B") c = (a + b) / 10 d = c + 1检查图输入和图输出
d.list_arguments() # ['A', 'B'] d.list_outputs() # ['_plusscalar0_output'] This is the default name from adding to scalar.
[2] mxnet实战