Skip to content
gotensorPublic

About

tensor for go

Resources

Stars

6 stars

Watchers

1 watching

Forks

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

gotensor

Build status go.dev reference Go Report Card

tensor package for golang

Install

go get -u github.com/gotensor/gotensor

How to use

Creating a new tensor:

data := []interface{}{1, 2, 3, 4, 5, 6}
shape := []int{2, 3}
tx := tensor.NewTensor(data, shape)

fmt.Println(tx)
// Shape: [2 3]
// 1 2 3
// 4 5 6

Creating a tensor with all zeros:

shape := []int{3, 3}
tx := tensor.Zeros(shape)

fmt.Println(tx)
// Shape: [3 3]
// 0 0 0
// 0 0 0
// 0 0 0

Creating a tensor with all ones:

shape := []int{2, 2}
tx := tensor.Ones(shape)

fmt.Println(tx)
// Shape: [2 2]
// 1 1
// 1 1

Getting a single value from the tensor:

data := []interface{}{1, 2, 3, 4, 5, 6}
shape := []int{2, 3}
tx := tensor.NewTensor(data, shape)
value, err := tx.Get(0, 1)
if err != nil {
    fmt.Println(err)
}
fmt.Println(value) // output: 2

Setting a single value in the tensor:

data := []interface{}{1, 2, 3, 4, 5, 6}
shape := []int{2, 3}
tx := tensor.NewTensor(data, shape)
err := tx.Set(7, 1, 2)
if err != nil {
    fmt.Println(err)
}
fmt.Println(tx)
// Shape: [2 3]
// 1 2 3
// 4 5 7

License

MIT

About

tensor for go

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages