I have a 3D numpy array representing an RGB image. I would like to fill the whole image with a particular RGB value. numpy.fill only takes a scalar as an argument-- is there a cleaner way than looping to assign the same third-dimension RGB triplet to each point in the 2d grid?
Maybe:
>>> m = np.zeros((2,2,3))
>>> m[:] = [10,20,3]
>>> m
array([[[ 10.,  20.,   3.],
        [ 10.,  20.,   3.]],
       [[ 10.,  20.,   3.],
        [ 10.,  20.,   3.]]])
>>> m[0,0]
array([ 10.,  20.,   3.])
>>> m[0,1]
array([ 10.,  20.,   3.])
>>> m[1,0]
array([ 10.,  20.,   3.])
>>> m[1,1]
array([ 10.,  20.,   3.])
                        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