How to pretty-print a numpy array without scientific notation and with given precision

0 votes

I Want to know  whether there is any way to print formatted numpy.arrays, e.g., in a way similar to this:

x = 1.23456
print '%.3f' % x

If I want to print the numpy.array of floats, it prints several decimals, often in 'scientific' format, which is rather hard to read even for low-dimensional arrays. However, numpy.array apparently has to be printed as a string, i.e., with %s. Is there a solution for this?

Apr 14, 2020 in Python by kartik
• 37,510 points
2,614 views

1 answer to this question.

0 votes

Hii @kartik,

The numpy arrays have the method round(precision) which return a new numpy array with elements rounded accordingly.

import numpy as np

x = np.random.random([5,5])
print(x.round(3))

Thank You!!

answered Apr 14, 2020 by Niroj
• 82,880 points

Related Questions In Python

+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,210 points

edited Aug 8, 2018 by Omkar 7,609 views
0 votes
1 answer
0 votes
0 answers
0 votes
1 answer

How to print a string with curly braces in Python?

You can use something like this - mystring ...READ MORE

answered Jul 23, 2019 in Python by Neel
• 3,020 points
11,493 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
+1 vote
12 answers
+1 vote
1 answer

How to convert a PIL Image into a numpy array?

Hello @kartik, You just need to convert your ...READ MORE

answered Jun 22, 2020 in Python by Niroj
• 82,880 points
3,867 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP