gorgonia / tensor

package tensor provides efficient and generic n-dimensional arrays in Go that are useful for machine learning and deep learning purposes
Apache License 2.0
359 stars 49 forks source link

Multidimensional array assignment #132

Open ashnair1 opened 2 years ago

ashnair1 commented 2 years ago

Given an array x of shape (3, 100, 100), does gorgonia/tensor have a way to do

x[0] = y
x[1] = z
x[2] = w

where w, y and z are of shape (100, 100)

yati-sagade commented 8 months ago

You can do something like:

import (
    "gorgonia.org/tensor"
)

...

s, err := x.Slice(tensor.S(0), nil, nil) // x[0, :, :]
if err != nil { ... }
tensor.Copy(s, y) // Note: dst, src.

s, err := x.Slice(tensor.S(1), nil, nil) // x[1, :, :]
if err != nil { ... }
tensor.Copy(s, z)

...