Why I am getting IndexError: tuple index out of range when converting a float value to a string?

Rob Gaddi rgaddi at highlandtechnology.invalid
Tue Jun 11 13:04:59 EDT 2019


On 6/11/19 9:52 AM, madhavanbomidi at gmail.com wrote:
> I wrote the following lines of code:
> 
> xm = np.nanmean(x[indx],axis=None,dtype=float)
> xsd = np.nanstd(x[indx],axis=None,dtype=float)
> 
> type(xm)    # np.float64
> type(xsd    # np.float64
> 
> print(xm)      # 0.5414720812182742
> print(xsd)     # 0.15748041033663002
> 
> print(str("{6.5f}".format(xm)))
> 
> I get the following error:
> 
> IndexError: tuple index out of range
> 
> Can someone suggest me why I am getting this error and how to overcome this?
> 
> Thanks in advance
> 

print(str("{:6.5f}".format(xm)))

You want to apply the format 6.5f to the autoindexed element.  You could 
also explicitly index the 1st element (#0) as {0:6.5f}.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list