Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathBasicOperations.fs
More file actions
Latest commit
49 lines (37 loc) · 1.39 KB
/
Copy pathBasicOperations.fs
File metadata and controls
49 lines (37 loc) · 1.39 KB
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
namespace TensorFlowNET.Examples.FSharp
open typeTensorflow.Binding
moduleBasicOperations =
letprivaterun()=
tf.enable_eager_execution()
// Define tensor constants.
leta= tf.constant(2)
letb= tf.constant(3)
letc= tf.constant(5)
// Various tensor operations.
// Note: Tensors also support operators (+, *, ...)
letadd= tf.add(a, b)
letsub= tf.subtract(a, b)
letmul= tf.multiply(a, b)
letdiv= tf.divide(a, b)
// Access tensors value.
print("add =", add.numpy())
print("sub =", sub.numpy())
print("mul =", mul.numpy())
print("div =", div.numpy())
// Some more operations.
letmean= tf.reduce_mean([| a; b; c |])
letsum= tf.reduce_sum([| a; b; c |])
// Access tensors value.
print("mean =", mean.numpy())
print("sum =", sum.numpy())
// Matrix multiplications.
letmatrix1= tf.constant(array2D [[1;2];[3;4]])
letmatrix2= tf.constant(array2D [[5;6];[7;8]])
letproduct= tf.matmul(matrix1, matrix2)
// Convert Tensor to Numpy.
print("product =", product.numpy())
true
letExample=
{ Config = ExampleConfig.Create ("Basic Operations", priority =2)
Run = run
}