theano学习——基本api

来源:互联网 发布:nginx http referer 编辑:程序博客网 时间:2024/06/15 13:48

theano 中数据类型与numpy 中的数据类型相互转化

  • (1)numpy ==> theano

    x = theano.shared(np.ones(3))
  • (2)theano ==> numpy(numpy.ndarray,多维数组)

    y = x.get_value()

theano.shared(borrow 参数)

考察其中的borrow参数(np.array vs np.asarray),涉及深拷贝和浅拷贝的区别:

import theano, numpynp_array = numpy.ones(2, dtype='float32')s_default = thenao.shared(np_array)s_false = theano.shared(np_array, borrow=False)s_true = theano.shared(np_array, borrow=True)
np_array += 1print(s_default.get_value())print(s_false.get_value())print(s_true.get_value())
[1. 1.][1. 1.][2. 2.]

theano.tensor.flatten(x, outdim=1)

详细文档见 flatten

x.shape == (2, 3, 4, 5)y = flatten(x, outdim=2)y.shape == (2, 3*4*5=60)
0 0
原创粉丝点击