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

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Build OCR from Scratch Python using YOLO and Tesseract
In this deep learning project, you will learn how to build your custom OCR (optical character recognition) from scratch by using Google Tesseract and YOLO to read the text from any images.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

PyTorch Project to Build a GAN Model on MNIST Dataset
In this deep learning project, you will learn how to build a GAN Model on MNIST Dataset for generating new images of handwritten digits.

Build an AI Chatbot from Scratch using Keras Sequential Model
In this NLP Project, you will learn how to build an AI Chatbot from Scratch using Keras Sequential Model.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Azure Deep Learning-Deploy RNN CNN models for TimeSeries
In this Azure MLOps Project, you will learn to perform docker-based deployment of RNN and CNN Models for Time Series Forecasting on Azure Cloud.

Build a Similar Images Finder with Python, Keras, and Tensorflow
Build your own image similarity application using Python to search and find images of products that are similar to any given product. You will implement the K-Nearest Neighbor algorithm to find products with maximum similarity.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.