It’s an old question but I’d add something potentially useful:
I know you wrote your example in raw Python lists, but if you decide to use numpy
arrays instead (which would be perfectly legit in your example, because you seem to be dealing with arrays of numbers), there is (almost exactly) this command you said you made up:
import numpy as np np.set_printoptions(precision=2)
Or even better in your case if you still want to see all decimals of really precise numbers, but get rid of trailing zeros for example, use the formatting string %g
:
np.set_printoptions(formatter={"float_kind": lambda x: "%g" % x})
For just printing once and not changing global behavior, use np.array2string
with the same arguments as above.
Related Posts:
- can’t multiply sequence by non-int of type ‘float’
- How do you round UP a number?
- How do you round UP a number?
- How to prettyprint a JSON file?
- (Python) TypeError: ‘float’ object is not subscriptable
- How do I parse a string to a float or int?
- Round a floating-point number down to the nearest integer?
- Limiting floats to two decimal points
- TypeError: ‘float’ object not iterable
- How to get a random number between a float range?
- How can I flush the output of the print function?
- How do I check if a string is a number (float)?
- How to print instances of a class using print()?
- Python, print all floats to 2 decimal places in output
- How can I print variable and string on same line in Python?
- How to truncate float values?
- Printing variables in Python 3.4
- Properly formatted multiplication table
- Python: Converting string into decimal number
- How to prettyprint a JSON file?
- Convert floats to ints in Pandas?
- In python, how can I print lines that do NOT contain a certain string, rather than print lines which DO contain a certain string:
- Using print() (the function version) in Python2.x
- Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
- Maximum and Minimum values for ints
- FileNotFoundError: [Errno 2] No such file or directory [duplicate]
- print variable and a string in python
- python capitalize first letter only
- Is there a short contains function for lists?
- ImportError: No module named pandas. Pandas installed pip
- How to Execute a Python Script in Notepad++?
- ValueError: operands could not be broadcast together with shapes (5,) (30,)
- What is the meaning of [:] in python [duplicate]
- Finding and replacing elements in a list
- socket.error: [Errno 48] Address already in use
- No module named MySQLdb
- TypeError: Missing 1 required positional argument: ‘self’
- Convert a tensor to numpy array in Tensorflow?
- How to import the class within the same directory or sub directory?
- Why do I get AttributeError: ‘NoneType’ object has no attribute ‘something’?
- What is __pycache__?
- Permission denied error by installing matplotlib
- Python equivalent of a given wget command
- How to find list intersection?
- Error while Executing jupyter notebook: [Errno 2] No such file or directory
- ValueError: max() arg is an empty sequence
- How do I insert a JPEG image into a python Tkinter window?
- In practice, what are the main uses for the new “yield from” syntax in Python 3.3?
- Subplot for seaborn boxplot
- Dump a NumPy array into a csv file
- How to delete a character from a string using Python
- What is the difference between sparse_categorical_crossentropy and categorical_crossentropy?
- Inverse of a matrix using numpy
- NameError: name ‘self’ is not defined
- gaierror: [Errno 8] nodename nor servname provided, or not known (with macOS Sierra)
- How to print colored text to the terminal
- TypeError: can only concatenate list (not “str”) to list
- What’s the idiomatic syntax for prepending to a short python list?
- What is the difference between “is None” and “== None”
- ImportError: No module named ‘Queue’
- ImportError: No Module Named bs4 (BeautifulSoup)
- How to calculate rolling / moving average using python + NumPy / SciPy?
- How to fix “Attempted relative import in non-package” even with __init__.py
- Errno 13 Permission denied Python
- How to get all possible combinations of a list’s elements?
- Converting strings to floats in a DataFrame
- Pylint “unresolved import” error in Visual Studio Code
- Errno 13 Permission denied Python
- ValueError: object too deep for desired array while using convolution
- How to convert string to binary?
- How to iterate through two lists in parallel?
- Make list of arrays in python
- Function to close the window in Tkinter
- Is there a way to specify which pytest tests to run from a file?
- Python function overloading
- Breaking out of nested loops
- Youtube_dl : ERROR : YouTube said: Unable to extract video data
- How to stop a function
- What is the common header format of Python files?
- How do I run pip on python for windows?
- How to get the text cursor position in Windows?
- python NameError: global name ‘__file__’ is not defined
- Rename specific column(s) in pandas
- How to create a numpy array of lists?
- Scikit-learn GridSearch giving “ValueError: multiclass format is not supported” error
- How to obfuscate Python code effectively?
- Controlling mouse with Python
- can we use XPath with BeautifulSoup?
- how to check which version of nltk, scikit learn installed?
- How do I add two sets?
- How to count the number of files in a directory using Python
- Counting array elements in Python
- Running shell command and capturing the output
- Determine if 2 lists have the same elements, regardless of order? [duplicate]
- Python copy files to a new directory and rename if file name already exists
- How to append new data onto a new line
- Building a list inside a list in python
- Python – difference between two strings
- Flask-framework: MVC pattern
- Installing win32gui python module