Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
19
Task/Identity-matrix/Go/identity-matrix-1.go
Normal file
19
Task/Identity-matrix/Go/identity-matrix-1.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gonum.org/v1/gonum/mat"
|
||||
)
|
||||
|
||||
func eye(n int) *mat.Dense {
|
||||
m := mat.NewDense(n, n, nil)
|
||||
for i := 0; i < n; i++ {
|
||||
m.Set(i, i, 1)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat.Formatted(eye(3)))
|
||||
}
|
||||
11
Task/Identity-matrix/Go/identity-matrix-2.go
Normal file
11
Task/Identity-matrix/Go/identity-matrix-2.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
mat "github.com/skelterjohn/go.matrix"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(mat.Eye(3))
|
||||
}
|
||||
17
Task/Identity-matrix/Go/identity-matrix-3.go
Normal file
17
Task/Identity-matrix/Go/identity-matrix-3.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
|
||||
func I(n int) [][]float64 {
|
||||
m := make([][]float64, n)
|
||||
for i := 0; i < n; i++ {
|
||||
a := make([]float64, n)
|
||||
a[i] = 1
|
||||
m[i] = a
|
||||
}
|
||||
return m
|
||||
}
|
||||
18
Task/Identity-matrix/Go/identity-matrix-4.go
Normal file
18
Task/Identity-matrix/Go/identity-matrix-4.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println(I(3))
|
||||
}
|
||||
|
||||
func I(n int) [][]float64 {
|
||||
m := make([][]float64, n)
|
||||
a := make([]float64, n*n)
|
||||
for i := 0; i < n; i++ {
|
||||
a[i] = 1
|
||||
m[i] = a[:n]
|
||||
a = a[n:]
|
||||
}
|
||||
return m
|
||||
}
|
||||
34
Task/Identity-matrix/Go/identity-matrix-5.go
Normal file
34
Task/Identity-matrix/Go/identity-matrix-5.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type matrix []float64
|
||||
|
||||
func main() {
|
||||
n := 3
|
||||
m := I(n)
|
||||
// dump flat represenation
|
||||
fmt.Println(m)
|
||||
|
||||
// function x turns a row and column into an index into the
|
||||
// flat representation.
|
||||
x := func(r, c int) int { return r*n + c }
|
||||
|
||||
// access m by row and column.
|
||||
for r := 0; r < n; r++ {
|
||||
for c := 0; c < n; c++ {
|
||||
fmt.Print(m[x(r, c)], " ")
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func I(n int) matrix {
|
||||
m := make(matrix, n*n)
|
||||
// a fast way to initialize the flat representation
|
||||
n++
|
||||
for i := 0; i < len(m); i += n {
|
||||
m[i] = 1
|
||||
}
|
||||
return m
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue