@999999999 the code from @jmaceiras works for me, and I think that’s a good solution. The one change I would make is to use torch::empty instead of torch::rand so you don’t have to compute random values that are immediately overwritten.