Return numpy array from python to Lazarus #488
Answered by pyscripter
Chemistza74 asked this question in Q&A
-
Hi, I've recently started playing around with P4D in Lazarus/FPC. I'm trying to read a numpy array created in python back in to FPC. The python code which I have in SynEdit1:
My attempt at the FPC code below to extract py_array is based on FPC Demo35:
However, when I run this, I only end up with a single, random number in ListBox1. Any suggestions on how to resolve this would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Answered by pyscripter Nov 28, 2024
Replies: 1 comment
-
If you run this code in PyScripter import numpy as np py_array = np.zeros(10) for i in range (10): py_array[i]=i print(py_array) The output is:
Notice that the values are floating point and you try to read them as Integers. I think if you change your code to: import numpy as np py_array = np.zeros(10, dtype= np.int32) for i in range (10): py_array[i]=i or simpler: import numpy as np py_array = np.array(range(10)) it should work. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by pyscripter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
If you run this code in PyScripter
The output is:
[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]
Notice that the values are floating point and you try to read them as Integers.
I think if you change your code to:
or simpler:
it should work.