[PictoBloxExtension]

Python math Module

Python-Programming
Extension Description
Built-in module for mathematical functions for programming in Python.

Introduction

Python Math Module is a built-in module that contains a large number of mathematical functions. This module is useful for dealing with mathematics-related tasks such as statistics, complex numbers, etc. The math module will also provide useful mathematical constants such as pi.

Definition and Usecase

The math module defines a wide range of useful mathematical functions that can be used directly in any Python program. The use case for Math Module ranges from basic arithmetic operations (such as addition, subtraction, division, etc.), to more complex operations (such as trigonometric functions, complex numbers, etc.).Examples with Output

Examples with Output

Example 1

Below is an example of using the math module to calculate the absolute value of a number.

import math 

# initializing the number 
number = -2.45 

# calculating absolute value of number 
absolute_value = math.fabs(number) 

# printing the absolute value 
print("Absolute value of",number,"is",absolute_value)

Output:

Absolute value of -2.45 is 2.45

Example 2

Below is the example of using math module to calculate the natural logarithm of a number.

import math

# initializing the number
number = 50

# calculating natural log of number
natural_log = math.log(number)

# printing the natural log of number
print("The natural log of", number, "is", natural_log)

Output:

The natural log of 50 is 3.912023005428146

Read More

Python Functions

The function reports the value of the JSON object from the body.
Syntax: getapijson(json1 = “value”, json2 = “”, json3 = “”, json4 = “”, json5 = “”)
The function reports the object count of the JSON object from the body.
Syntax: getobjectcountapijson(json1 = “value”, json2 = “”, json3 = “”, json4 = “”)
The function is used to control the state of the camera.
Syntax: video(video_state = “on”, transparency = 1)
The function enables the automatic display of the box on object detection on the stage.
Syntax: enablebox()
The function disables the automatic display of the box on object detection on the stage.
Syntax: disablebox()
This function is used to set the threshold for the confidence (accuracy) of object detection, 0 being low confidence and 1 being high confidence.
Syntax: setthreshold(threshold = 0.5)
This function is used to analyze the image received as input from the camera, for objects.
Syntax: analysecamera()
This function is used to analyze the image received as input from the stage, for objects.
Syntax: analysestage()
This function returns the total number of objects detected in the camera feed or the stage.
Syntax: count()
This function returns the x position of the object detected. You can specify the object for which the value is needed. The position is mapped with the stage coordinates.
Syntax: x(object = 1)
This function returns the y position of the object detected. You can specify the object for which the value is needed. The position is mapped with the stage coordinates.
Syntax: y(object = 1)
This function returns the width of the object detected. You can specify the object for which the value is needed. The position is mapped with the stage coordinates.
Syntax: width(object = 1)
This function returns the height of the object detected. You can specify the object for which the value is needed. The position is mapped with the stage coordinates.
Syntax: height(object = 1)
This function is used to get the class name of the analyzed object.
Syntax: classname(object = 1)
This function is used to get the confidence (accuracy) of object detection, 0 being low confidence and 1 being high confidence.
Syntax: confidence(object = 1)
The function returns whether the specified object is detected in the analysis or not. 
Syntax: isdetected(object_name = “person”)
The function returns whether the number of objects identified with the specified object class.
Syntax: detectedcount(object_name = “person”)
The function runs an API call to get the weather data of the location specified with the Longitude and Latitude.
Syntax: getweather(latitude = 23.02, longitude = 72.57)
The function returns the weather parameters (Rain, Snow, Extreme, etc.) of the location.
Syntax: weather()
The function returns the temperature, minumun, and maximum temperature of the location.
Syntax: temp(temp_type = “C”)
The function returns the atmospheric pressure (on the sea level, if there is no sea_level or grnd_level data), in hPa of the location.
Syntax: pressure()
The function returns the humidity in % of the location.
Syntax: humidity()
The function returns the wind speed (Unit Default: meter/sec) of the location.
Syntax: windspeed()
The function returns the wind direction (in degrees – meteorological) of the location.
Syntax: winddirection()
The function returns the latitude of the location.
Syntax: latitude()
The function returns the longitude of the location.
Syntax: longitude()
The function returns the time data of the location when data capture, sunrise, or sunset happens.
Syntax: time(capture_time = “sunrise”)
The function returns the city name of the location.
Syntax: city()
The function set the API keys for the Open Weather Map API calls.
Syntax: setAPI(openweathermap_API)
The function is used to control the state of the camera.
Syntax: video(video_state = “on”, transparency = 1)
All articles loaded
No more articles to load
Table of Contents