-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensors.fsx
37 lines (23 loc) · 1003 Bytes
/
tensors.fsx
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
#r "nuget: DiffSharp-lite,1.0.7"
(**
[](https://colab.research.google.com/github/DiffSharp/diffsharp.github.io/blob/master/tensors.ipynb) 
[](https://mybinder.org/v2/gh/diffsharp/diffsharp.github.io/master?filepath=tensors.ipynb) 
[](tensors.fsx) 
[](tensors.ipynb)
* The [dsharp](https://diffsharp.github.io/reference/diffsharp-dsharp.html) API
* The [Tensor](https://diffsharp.github.io/reference/diffsharp-tensor.html) type
Saving tensors as image and loading images as tensors
## Converting between Tensors and arrays
System.Array and F# arrays
*)
open DiffSharp
// Tensor
let t1 = dsharp.tensor [ 0.0 .. 0.2 .. 1.0 ]
// System.Array
let a1 = t1.toArray()
// []<float32>
let a1b = t1.toArray() :?> float32[]
// Tensor
let t2 = dsharp.randn([3;3;3])
// [,,]<float32>
let a2 = t2.toArray() :?> float32[,,]