-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtensor.go
More file actions
50 lines (44 loc) · 821 Bytes
/
tensor.go
File metadata and controls
50 lines (44 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
///main package has examples shown
// in Go Data Structures and algorithms book
package main
// importing fmt package
import (
"fmt"
"math/rand"
)
//main method
func main() {
var array [3][3][3]int
var i int
var j int
var k int
for i = 0; i < 3; i++ {
for j = 0; j < 3; j++ {
for k = 0; k < 3; k++ {
array[i][j][k] = rand.Intn(3)
}
}
}
fmt.Println(array)
fmt.Println("zero mode unfold")
for j = 0; j < 3; j++ {
for k = 0; k < 3; k++ {
fmt.Printf("%d ", array[0][j][k])
}
fmt.Printf("\n")
}
fmt.Println("1-mode unfold")
for j = 0; j < 3; j++ {
for k = 0; k < 3; k++ {
fmt.Printf("%d ", array[1][j][k])
}
fmt.Printf("\n")
}
fmt.Println("2-mode unfold")
for j = 0; j < 3; j++ {
for k = 0; k < 3; k++ {
fmt.Printf("%d ", array[2][j][k])
}
fmt.Printf("\n")
}
}