Skip to content

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

@francesco123212

Description

@francesco123212

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions