1

In R, I have been trying to use Tensorflow math functions. My issue is I can't figure out how to enter arguments into the tensorflow functions like you can with Python.

For example, how can I do the tensorflowdot function?

x = tf$constant(c(1, 2, 3))
y = tf$constant(c(9, 8, 7))
tf$tensordot(x, y, axes = 1)
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  TypeError: Cannot convert 1.0 to EagerTensor of dtype int32 

I can reproduce the output of tensordot manually, but I want to use the built in

tf$reduce_sum(x * y)
Frank
  • 952
  • 1
  • 9
  • 23

1 Answers1

3

The axes value is parsed as a float, not an integer. Fixing it as an integer resolves the error:

> tf$tensordot(x, y, axes = 1L) 
tf.Tensor(46.0, shape=(), dtype=float32)

This is related to how R defines numeric data types.

is.integer(1) # FALSE
is.double(1) # TRUE

is.integer(1L) # TRUE
is.double(1L) # FALSE
andrew_reece
  • 20,390
  • 3
  • 33
  • 58