floor function in numpy and ceil function in numpy array
In this numpy tutorial, we will discuss about:
-
floor function in numpy,
-
ceil function in numpy
Here we are going to apply floor function in numpy and ceil function in numpy array but before that lets learn a bit about numpy.
numpy stands for numeric python which is used to perform mathematical operations on arrays.
It is a module in which we have to import from the python.
Syntax to import:
import numpy
We can also use alias for the module
For example,
import numpy as np
We can directly use np to call the numpy module.
Array in numpy
An array is an one dimensional data structure used to store single data type data.
I.E It will only store all integer data or all string type data.or all float type data.
We can create an numpy array by using array() function.
Syntax:
numpy.array(elements)
where, elements are the input data elements.
floor function in numpy
floor function in numpy or floor() is used to get the element/integer value from the float value below to the decimal value of the actual float element.
Syntax: floor in numpy
numpy.floor(array_input)
where, array_input is the input array.
Example: floor in numpy
floor function in numpy helps get the floor value in numpy of the elements from the given array.
#importing the numpy module
import numpy
#create array with 5 float values
array_data=numpy.array([10.7,20.3,30.2,50.0,78.90])
#actual array
print(array_data)
print()
#get the floor values
print(numpy.floor(array_data))
Output:
We created an array with 5 float values and applied floor() function on the array to get floor value in numpy.
[10.7 20.3 30.2 50. 78.9]
[10. 20. 30. 50. 78.]
This way we can use floor in numpy to get floor value in numpy
ceil function in numpy
ceil function in numpy or ceil() is used to get the element/integer value from the float value above to the decimal value of the actual float element.
Syntax: ceil in numpy
numpy.ceil(array_input)
where, array_input is the input array.
Example: ceil in numpy
ceil in numpy helps get the ceil value numpy of the elements from the given array.
#importing the numpy module
import numpy
#create array with 5 float values
array_data=numpy.array([10.7,20.3,30.2,50.0,78.90])
#actual array
print(array_data)
print()
#get the ceil values
print(numpy.ceil(array_data))
Output:
We created an array with 5 float values and applied ceil function in numpy on the array.
[10.7 20.3 30.2 50. 78.9]
[11. 21. 31. 50. 79.]
This wraps up our session on floor function in numpy and ceil function in numpy.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Gottumukkala Sravan Kumar 171FA07058
B.Tech (Hon's) - IT from Vignan's University.
Published 1400+ Technical Articles on Python, R, Swift, Java, C#, LISP, PHP - MySQL and Machine Learning
Page Views :
Published Date :
Sep 10,2022