Multiply raster by Numpy derived float value

Multiply raster by Numpy derived float value

So I have a python script that uses numpy to calculate the mean of a field, then I try to use that mean value in a raster multiplication as follows:

na = arcpy.da.TableToNumPyArray("%SCRATCHWORKSPACE%
c_instruments_sr_noNULL2", "ratio") dMeanRatio = numpy.mean(na["ratio"]) outCorrectedSR = Raster(outSimulated) * dMeanRatio

This gives an error of:

TypeError: expected a raster or layer name

This error is not referring to "Raster(outSimulated)" because I've replaced dMeanRatio with a hard-coded value and the script runs just fine. So my question is, how do I convert the dMeanRatio into a value that is acceptable to the raster multiplication?

Got it figured out! Thanks to @Aaron's comments I was able to find a conversion:

dMeanRatio2 = numpy.asscalar(dMeanRatio)

Watch the video: Python NumPy For Your Grandma - NumPy Array Basics