Following is the code I am trying to use to get my result, and I am getting an error:
import numpy
array = [-1000,0,0,1094.60,0,0,1094.60]
for b in array:
a = round(numpy.irr(array), b-1) * 100
print (round(a,2))
Error:
TypeError: 'float' object cannot be interpreted as an integer
But, just replacing that "b-1" makes my code work, but I can't use that because array could be as large or as small as possible. I am not allowed to manually enter numbers replacing that "b-1". Following is the same working code.
import numpy
array = [-1000,0,0,1094.60,0,0,1094.60]
for b in array:
a = round(numpy.irr(array), 6) * 100
print (round(a,2))
I need a way to do it automatically for any size of array.
You got the error because you tried to to round the rate to 1093.60 decimal places (that's b-1 for the 4th iteration).
numpy.arr works on any size of array. You do not have to give it a size (and you didn't). I gather that you're trying to print the interest rate as a percentage, rounded to 2 decimal places. Use this instead:
Using this at the end of the code I gave you earlier gives this output for comparison: