Week 3 programming assignment sigmoid function

Hi, I’m having problems with the first line casting the tensor for the sigmoid function I assume it’s float32, but I don’t understand what tensor it should be, I’m using Z = tf.cast(“X”, tf.float32) please advise thanks

Hi @loughp,

There is one input “z” that needs to be tf.float32 that’s why it must be cast. I didn’t understand what “X” represents in your code.
With that, please refrain from posting the code directly. You may send a PM to me if you want to ask something related with your code.


1 Like

Thanks when I use z i get the following error can’t cast string to float, I’ve tried not using quotation marks in the tf.cast as well, so I’ve tried tf.cast(" ", float32) and tf.cast( , float32) with no quotation marks, thanks

UnimplementedError Traceback (most recent call last)
----> 1 result = sigmoid(-1)
2 print ("type: " + str(type(result)))
3 print ("dtype: " + str(result.dtype))
4 print ("sigmoid(-1) = " + str(result))
5 print ("sigmoid(0) = " + str(sigmoid(0.0)))

in sigmoid(z)
16 # (approx. 2 lines)
—> 17 x = tf.cast(“z”, tf.float32)
18 a = tf.keras.activations.sigmoid(“x”)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 “”“Call target, and fall back on dispatchers if there is a TypeError.”""
200 try:
→ 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in cast(x, dtype, name)
921 x = ops.convert_to_tensor(x, name=“x”)
922 if x.dtype.base_dtype != base_type:
→ 923 x = gen_math_ops.cast(x, base_type, name=name)
924 if x.dtype.is_complex and base_type.is_floating:
925 logging.warn(“Casting complex to real discards imaginary part.”)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in cast(x, DstT, Truncate, name)
1856 return _result
1857 except _core._NotOkStatusException as e:
→ 1858 _ops.raise_from_not_ok_status(e, name)
1859 except _core._FallbackException:
1860 pass

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name)
6841 message = e.message + (" name: " + name if name is not None else “”)
6842 # pylint: disable=protected-access
→ 6843 six.raise_from(core._status_to_exception(e.code, message), None)
6844 # pylint: enable=protected-access

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

UnimplementedError: Cast string to float is not supported [Op:Cast]

Sorry I worked this out just a syntax problem thanks

1 Like

please elaborate more am facing the same problem