1

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%\\rc_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?

  • I should clarify that dMeanRatio is being calculated correctly. – GISUser9 Oct 16 '14 at 19:55
  • What do you get when you run type(dMeanRatio) in Python? – Aaron Oct 16 '14 at 20:00
  • <type 'numpy.float32'> – GISUser9 Oct 16 '14 at 20:02
  • Have you tried float(dMeanRatio)? – Aaron Oct 16 '14 at 20:50
1

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

dMeanRatio2 = numpy.asscalar(dMeanRatio)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.