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 in Python by kartik
• 15,480 points
160 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 by Niroj
• 32,280 points

Related Questions In Python

+2 votes
11 answers
+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 4, 2018 in Python by Omkar
• 69,040 points

edited Aug 8, 2018 by Omkar 3,591 views
0 votes
1 answer
0 votes
0 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,047 views
0 votes
0 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 in Python by Niroj
• 32,280 points
22 views
0 votes
1 answer

How does numpy.newaxis work and when to use it?

Hello, The np.newaxis is generally used with slicing. It indicates ...READ MORE

answered Apr 14 in Python by Niroj
• 32,280 points
577 views