Hi, I am trying to store data on the SD card on my PYBD-SF6W. I am running Micropython v1.13-150-gb7883ce74. I am able to write strings to '.txt' files no problem. I can also write dictionaries that contain numpy arrays to '.json' files without any issues. However, when I try to write numpy arrays directly to '.txt' or '.DAP' files, I receive fatal errors:
Does anyone have an idea as to why this might be happening? I did not have this issue on Micropython v1.12.
Unable to write numpy arrays to '.txt' or '.DAP' files on SD
Re: Unable to write numpy arrays to '.txt' or '.DAP' files on SD
My understanding is that f.write(data) should attempt to call mp_get_buffer_raise on the ulab array type.
To isolate the problem, can you try doing
Code: Select all
import ulab as np
data = np.zeros((3,3))
buf = bytes(data)
print(buf)
Re: Unable to write numpy arrays to '.txt' or '.DAP' files on SD
Upon trying to that code, after typing buf = bytes(data), it stalled and then errored, and I wasn't even able to type print(buf):jimmo wrote: ↑Mon Jan 11, 2021 1:04 amMy understanding is that f.write(data) should attempt to call mp_get_buffer_raise on the ulab array type.
To isolate the problem, can you try doing
That will at least check whether there's something going wrong with file i/o or with ulab's implementation of mp_get_buffer_raise.Code: Select all
import ulab as np data = np.zeros((3,3)) buf = bytes(data) print(buf)
Re: Unable to write numpy arrays to '.txt' or '.DAP' files on SD
I think this might be worth raising at https://github.com/v923z/micropython-ulab
-
- Posts: 15
- Joined: Sat Jan 11, 2020 2:31 pm
Re: Unable to write numpy arrays to '.txt' or '.DAP' files on SD
As a workaround you can use the .flatten().tobytes() methods.
This won't give you an error, however it doesn't function properly. I think there may be a bug in the .tobytes() file as the lenght of the array is off by a factor of 8 (the size of float object).
Code: Select all
a = np.zeros((1,1))
b = a.flatten().tobytes()
Re: Unable to write numpy arrays to '.txt' or '.DAP' files on SD
You could try again, this bug was just fixed a couple of hours ago.monquarter wrote: ↑Mon Jan 11, 2021 5:20 pmThis won't give you an error, however it doesn't function properly. I think there may be a bug in the .tobytes() file as the lenght of the array is off by a factor of 8 (the size of float object).