我正在学习张量流,我知道我可以做到numpy
a = np.random.randn(1,2,3)
a[a<0.5] = -1
我怎样才能在张量流中做同样的事情?谢谢!
答案 0 :(得分:1)
[[[-2.36796331 -0.29641244 1.46340346]
[-0.38756183 -0.39763084 -0.34627825]]]
[[[-1. -1. 1.46340346]
[-1. -1. -1. ]]]
输出:
foreach ($array as $key => $value) { // Loop to result array
if (count($value) <= 1) { // Checks if array count is less than or equal to 1
$array[$key] = reset($value); // Reset to reduce from 2d array to 1d
}
}
print_r($array);