mxnet基础到提高(11)--循环
mxnet.ndarray.contrib.foreach(body, data, init_states)
運行循環,在NDArrays在0維度上使用用戶定義的計算
這個操作
這個操作符模擬了一個for循環,并且body有一個for循環迭代的計算。body以兩個參數作為輸入,并輸出兩個元素的元組,如下所示:
out, states = body(data1, states)
data1是NDArray的列表或NDArray,如果data是一個NDArray,則data1是一個NDArray,否則,data1是一個NDArrays的列表且有和data同樣的大小。states是一個NDArrays的列表,有與init_states相同的大小。out是NDArray或NDArray的列表,它被連接為為foreach第一個輸出。states來自body的最后執行,是foreach的第二個輸出。
當輸入數據是NDArray時,這個操作符所做的計算相當于下面的偽代碼:
states = init_states outs = [] for i in data.shape[0]:
s = data[i] out, states = body(s, states) outs.append(out)
outs = stack(*outs)
Parameters:
body (a Python function.) – Define computation in an iteration.
data (an NDArray or a list of NDArrays.) – The input data.
init_states (an NDArray or nested lists of NDArrays.) – The initial values of the loopstates.
name (string.) – The name of the operator.
Returns:
outputs (an NDArray or nested lists of NDArrays.) – The output data concatenated from the output of all iterations.
states (an NDArray or nested lists of NDArrays.) – The loop states in the last iteration.
Examples
總結
以上是生活随笔為你收集整理的mxnet基础到提高(11)--循环的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mxnet基础到提高(10)--读写文件
- 下一篇: .net随笔-vb.net 系统计时器