Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer division operation yields float #21093

Open
cod3monk opened this issue Mar 15, 2021 · 1 comment
Open

Integer division operation yields float #21093

cod3monk opened this issue Mar 15, 2021 · 1 comment

Comments

@cod3monk
Copy link

cod3monk commented Mar 15, 2021

import sympy
import numpy

i = sympy.var('i', integer=True)

# lambdify function with integer division (//)
f = i // 3
lf = sympy.lambdify(i, f, modules='numpy')

# map to array of integers
lf(numpy.arange(0, 10, dtype='int64'))

while the integer division is correctly done with floor and /, this gives an array of floats (array([0., 0., 0., 1., 1., 1., 2., 2., 2., 3.])), but I would expect an array of integers (array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3])) as i is an integer, // gives an integer and the input datatype is also an integer. Is there anyway to force returned types?

@Simardeep27
Copy link

I can confirm this issue.

If you want to force the returned type, you can use numpy.vectorize(sympy.lambdify(i,f, modules='numpy'),otypes=[int]), you can set the output data type using otype parameter.

You can view this link for np.vectorize : ( https://numpy.org/doc/stable/reference/generated/numpy.vectorize.html )

This issue was raise earlier too , you can refer to #5642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants