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

PyObject array 'only size-1 arrays can be converted to Python scalars' #984

Closed
francesco123212 opened this issue Apr 16, 2022 · 2 comments
Closed

Comments

@francesco123212
Copy link

francesco123212 commented Apr 16, 2022

Hi, hope you all are healthy.
Sorry for the basic question, I am working with ansys.mapdl.core and with the function mapdl.mesh.nodes I get a pyObject array of the form:

example = 
PyObject array([[ 2.12132034e-01,  2.12132034e-01,  2.12132034e-01],
       [ 2.28079876e-01,  1.94883478e-01,  2.28079876e-01],
       .
       .
       .
       [-1.38362452e-01,  2.45949820e-01,  2.52261847e-01]])

To convert it to a Julia array I try to use convert(Matrix{Float64}, example) and I get the following error:

PyError (ccall(#= C:\Users\frcol\.julia\packages\PyCall\7a7w0\src\conversions.jl:59 =# @pysym(:PyFloat_AsDouble), Cdouble, (PyPtr,), po)) <class 'TypeError'>
TypeError('only size-1 arrays can be converted to Python scalars')

I guess it is very similar to the issue https://github.com/JuliaPy/PyCall.jl/issues/99.
I also tried the following:

julia> o1 = PyObject(rand(2,3))
PyObject array([[0.87548089, 0.45301964, 0.18828053],
       [0.96245816, 0.29647598, 0.42078386]])

julia> convert(Matrix{Float64}, o1)
2×3 Matrix{Float64}:
 0.875481  0.45302   0.188281
 0.962458  0.296476  0.420784

and it works fine. Could you please tell me what I do wrong? Thanks

@stevengj
Copy link
Member

Probably ansys.mapdl.core is not returning a numpy array, but instead just a list of lists.

What happens if you just do convert(PyAny, example) to let PyCall decide how to convert it?

@francesco123212
Copy link
Author

it works thankyou!

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

No branches or pull requests

2 participants