Unsupported Format String Passed to Numpy. Ndarray

Unsupported Format String Passed to Numpy. Ndarray

Let's say I have the array:

import numpy as np
x = np.array([1.2334, 2.3455, 3.456], dtype=np.float32)

and want to print:

print('{:.2f}%'.format(x))

It gives me:

unsupported format string passed to numpy.ndarray.__format__
4

2 Answers

If you still want format

list(map('{:.2f}%'.format,x))
Out[189]: ['1.23%', '2.35%', '3.46%']
0

Try this:

x = np.array([1.2334, 2.3455, 3.456], dtype=np.float32)

x= list(map(lambda x :str(x) + '%',x.round(2)))
print(f'{x}')

It would print:

['1.23%', '2.35%', '3.46%']

Your Answer

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

Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.