When I try to use the library CuPy with osgeo, I'm facing this error:
ValueError: non-scalar numpy.ndarray cannot be used for fill
I'm trying to fill this array:
im = cupy.zeros([ds.RasterYSize, ds.RasterXSize, ds.RasterCount], dtype=np.float32)
for x in range(1, ds.RasterCount + 1):
band = ds.GetRasterBand(x)
im[:, :, x - 1] = band.ReadAsArray() #error here
Any fixes for this?
Because of CuPy library works with GPUs, you can't access to the memory of the CPU. You have created im as a cupy array.
Osgeo uses Numpy, not Cupy, so you need to pass the array generated by numpy with this command to the GPU memory:
im[:, :, x - 1] = cupy.asarray(band.ReadAsArray())
See the official documentation here: https://docs.cupy.dev/en/stable/reference/generated/cupy.asarray.html
Check also this: https://docs.cupy.dev/en/stable/reference/generated/cupy.asnumpy.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With