What is the number class in Sympy

This recipe explains what is the number class in Sympy

Recipe Objective - What is the number class in Sympy?

The main module of the SymPy package contains the class number, which represents ordinal numbers. This class has two subclasses: Float class and Rational. The rational class is extended with the entire class.

Learn to Implement Customer Churn Prediction Using Machine Learning in Python 

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects
https://www.projectpro.io/projects/data-science-projects/tensorflow-projects

The Float class represents a floating-point number of any precision.

from sympy import Float
print("1.69 => ",Float(1.69))
print("2 => ",Float(2))

# Define how many decimal position
print("2.34 => ",Float(2.34,2))

Output - 
1.69 =>  1.69000000000000
2 =>  2.00000000000000
2.34 =>  2.3

Rational class:

from sympy import Rational
# A representation of a number (a / b) is represented as an object of class Rational, where b is a nonzero number.
Rational(1/2)

Output - 
1
-
2

from sympy import Rational
# When a floating point number is passed to the Rational () constructor, it returns the underlying value of its binary representation
Rational(0.12)

Output - 
1080863910568919
----------------
9007199254740992

from sympy import Rational
# When a string is passed to the Rational () constructor, a rational number of arbitrary precision is returned.
Rational("0.12")

Output - 
 3
--
25

In this way, we can use the number class in SymPy.

What Users are saying..

profile image

Ed Godalle

Director Data Analytics at EY / EY Tech
linkedin profile url

I am the Director of Data Analytics with over 10+ years of IT experience. I have a background in SQL, Python, and Big Data working with Accenture, IBM, and Infosys. I am looking to enhance my skills... Read More

Relevant Projects

Insurance Pricing Forecast Using XGBoost Regressor
In this project, we are going to talk about insurance forecast by using linear and xgboost regression techniques.

Expedia Hotel Recommendations Data Science Project
In this data science project, you will contextualize customer data and predict the likelihood a customer will stay at 100 different hotel groups.

Build a Graph Based Recommendation System in Python -Part 1
Python Recommender Systems Project - Learn to build a graph based recommendation system in eCommerce to recommend products.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Image Classification Model using Transfer Learning in PyTorch
In this PyTorch Project, you will build an image classification model in PyTorch using the ResNet pre-trained model.

End-to-End Snowflake Healthcare Analytics Project on AWS-1
In this Snowflake Healthcare Analytics Project, you will leverage Snowflake on AWS to predict patient length of stay (LOS) in hospitals. The prediction of LOS can help in efficient resource allocation, lower the risk of staff/visitor infections, and improve overall hospital functioning.

Loan Default Prediction Project using Explainable AI ML Models
Loan Default Prediction Project that employs sophisticated machine learning models, such as XGBoost and Random Forest and delves deep into the realm of Explainable AI, ensuring every prediction is transparent and understandable.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT

Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.