Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValueError: non-scalar numpy.ndarray cannot be used for fill - CuPy

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?

like image 711
Francesco Laiti Avatar asked Oct 27 '25 04:10

Francesco Laiti


1 Answers

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

like image 127
Francesco Laiti Avatar answered Oct 29 '25 18:10

Francesco Laiti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!