Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Stop Sage from overriding Python number types

I'm trying to play around with machine learning inside of the SageMath environment, but since Sage implicitly casts ints, floats, etc. to Integers, RealNumbers, etc., I'm running into problems such as this one:

... --> model.add(Dense(Integer(1), activation="softmax")) ... ValueError: Can't convert Python sequence with mixed types to Tensor.

So far, I've gotten around this by explicitly casting, so my line of code now looks like this:

... model.add(Dense(int(1), activation="softmax")) ...

but I would rather not do this every time I create a model. Is there a way to stop Sage from implicitly casting, and instead use the default Python types?