8000 GitHub - gotensor/gotensor: tensor for go
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

gotensor/gotensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0