It acts as an unbounded upper value for comparison. This is useful for finding lowest values for something. for example, calculating path route costs when traversing trees.
e.g. Finding the “cheapest” path in a list of options:
>>> lowest_path_cost = float('inf') >>> # pretend that these were calculated using some worthwhile algorithm >>> path_costs = [1, 100, 2000000000000, 50] >>> for path in path_costs: ... if path < lowest_path_cost: ... lowest_path_cost = path ... >>> lowest_path_cost 1
if you didn’t have float('Inf')
available to you, what value would you use for the initial lowest_path_cost
? Would 9999999
be enough — float('Inf')
removes this guesswork.
Related Posts:
- Python – TypeError: ‘int’ object is not iterable
- are there dictionaries in javascript like python?
- How do I update\upgrade pip itself from inside my virtual environment?
- What does the “yield” keyword do?
- Renaming column names in Pandas
- Does Python have a string ‘contains’ substring method?
- Is there a “not equal” operator in Python?
- IndexError: list index out of range and python
- Python: ‘ModuleNotFoundError’ when trying to import module from imported package
- Check if a given key already exists in a dictionary
- ValueError: setting an array element with a sequence
- ‘python’ is not recognized as an internal or external command [duplicate]
- `from … import` vs `import .` [duplicate]
- How to read a text file into a string variable and strip newlines?
- ln (Natural Log) in Python
- How do I select rows from a DataFrame based on column values?
- How to round to 2 decimals with Python?
- How do I concatenate two lists in Python?
- How do I get the row count of a Pandas DataFrame?
- python : comma in print as “\t”
- How can I randomly select an item from a list?
- Python Error: AttributeError: __enter__ [duplicate]
- How to plot a histogram using Matplotlib in Python with a list of data?
- Convert pandas dataframe to NumPy array
- Fastest way to check if a value exists in a list
- TypeError: can’t multiply sequence by non-int of type ‘str’
- Error:cannot convert float NaN to integer in pandas
- Get a list from Pandas DataFrame column headers
- ‘End of statement expected’ in pycharm
- How to import files in python using sys.path.append?
- Tensorflow: why ‘pip uninstall tensorflow’ cannot find tensorflow
- TypeError: object of type ‘int’ has no len() – Python/Pygame
- Python: Open file in zip without temporarily extracting it
- Installing tensorflow with anaconda in windows
- Plotting multiple different plots in one figure using Seaborn
- What does “unsqueeze” do in Pytorch?
- Delete an element from a dictionary
- Change figure size and figure format in matplotlib
- How can I concatenate str and int objects?
- Python Calling Function from Another File
- error: Unable to find vcvarsall.bat
- pg_config executable not found
- error: Failed to load the native TensorFlow runtime
- How do I check if a list is empty?
- List files ONLY in the current directory
- Most efficient way to reverse a numpy array
- Python return list from function
- Remove all special characters, punctuation and spaces from string
- How to delete last item in list?
- How to configure logging to syslog in Python?
- Converting binary to decimal integer output
- Don’t understand this SyntaxError: illegal target for annotation
- No module named setuptools
- Using Queue in python
- Whats the difference between ‘for x in list:’ and ‘for x in list[:]:’
- ctypes error: libdc1394 error: Failed to initialize libdc1394
- Python: cannot concatenate ‘str’ and ‘int’ objects error
- How to “test” NoneType in python?
- AttributeError:’bytes’ object has no attribute ‘encode’
- python mpl_toolkits installation issue
- What does bitwise_and operator exactly do in openCV?
- RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility
- Using BeautifulSoup to search HTML for string
- TensorFlow: Blas GEMM launch failed
- Python Weather API
- How do I get time of a Python program’s execution?
- Pandas DataFrame: replace all values in a column, based on condition
- How to create a trie in Python
- How to convert string to datetime format in pandas python?
- Find which version of package is installed with pip
- What do the python file extensions, .pyc .pyd .pyo stand for?
- How to start from second index for for-loop
- Python: How to check if keys exists and retrieve value from Dictionary in descending priority
- Python: Converting string into decimal number
- Segmentation fault: 11 in OS X
- Removing duplicates from a list of lists
- Importing Pandas gives error AttributeError: module ‘pandas’ has no attribute ‘core’ in iPython Notebook
- What does this Django regular expression mean? `?P`
- Strange error about invalid syntax
- ‘virtualenv’ is not recognized as an internal or external command, operable program or batch file
- Python Coin Toss
- Is it better to use path() or url() in urls.py for django 2.0?
- gunicorn.errors.HaltServer:
django - What is a clean, Pythonic way to have multiple constructors in Python?
- Python Login Script; Usernames and Passwords in a separate file
- Ignore .pyc files in git repository
- MovieWriter ffmpeg unavailable; trying to use class ‘matplotlib.animation.PillowWriter’ instead
- How can I access global variable inside class in Python
- Sorting arrays in NumPy by column
- How to open html file?
- In Python, is there an elegant way to print a list in a custom format without explicit looping?
- “Python version 2.7 required, which was not found in the registry” error when attempting to install netCDF4 on Windows 8
- Does tkinter have a table widget?
- Python 2.7 mixing iteration and read methods would lose data
- Conditional indexing with Numpy ndarray
- python numpy machine epsilon
- Installing lxml module in python
- Extracting specific selected columns to new DataFrame as a copy
- How to read a CSV file from a URL with Python?
- How to print both strings in a dictionary in Python