Python | Numpy matrix.round() (original) (raw)
Last Updated : 23 Apr, 2019
With the help of **Numpy matrix.round()**
method, we are able to round off the values of the given matrix.
Syntax :
matrix.round()
Return : Return rounded values in matrix
Example #1 :
In the given example we are able to round off the given matrix by using matrix.round()
method.
import
numpy as np
gfg
=
np.matrix(
'[6.4, 1.3; 12.7, 32.3]'
)
geeks
=
gfg.
round
()
print
(geeks)
Output:
[[ 6. 1.] [ 13. 32.]]
Example #2 :
import
numpy as np
gfg
=
np.matrix(
'[1.2, 2.3; 4.7, 5.5; 7.2, 8.9]'
)
geeks
=
gfg.
round
()
print
(geeks)
Output:
[[ 1. 2.] [ 5. 6.] [ 7. 9.]]
Similar Reads
- numpy.round_() in Python The round_() function in NumPy rounds the elements of an array to a specified number of decimal places. This function is extremely useful when working with floating-point numbers and when precision is important in scientific computing or data analysis. Syntax: numpy.round_(arr, decimals=0, out=None) 3 min read
- Python | Numpy matrix.resize() With the help of Numpy matrix.resize() method, we are able to resize the shape of the given matrix. Remember all elements should be covered after resizing the given matrix. Syntax : matrix.resize(shape) Return: new resized matrix Example #1 : In the given example we are able to resize the given matr 1 min read
- Python | Numpy matrix.take() With the help of Numpy matrix.take() method, we can select the elements from a given matrix by passing the parameter as index value of that element. It will return a matrix having one dimension. Remember it will work for one axis at a time. Syntax : matrix.take(index, axis) Return : Return matrix of 1 min read
- numpy.matrix() in Python This class returns a matrix from a string of data or array-like object. Matrix obtained is a specialised 2D array. Syntax : numpy.matrix(data, dtype = None) : Parameters : data : data needs to be array-like or string dtype : Data type of returned array. Returns : data interpreted as a matrix # Pytho 1 min read
- Python | Numpy matrix.squeeze() With the help of matrix.squeeze() method, we are able to squeeze the size of a matrix by using the same method. But remember one thing we use this method on Nx1 size of matrix which gives out as 1xN matrix. Syntax : matrix.squeeze() Return : Return a squeezed matrix Example #1 : In this example we a 1 min read
- Python | Numpy matrix.transpose() With the help of Numpy matrix.transpose() method, we can find the transpose of the matrix by using the matrix.transpose()method in Python. Numpy matrix.transpose() Syntax Syntax : matrix.transpose() Parameter: No parameters; transposes the matrix it is called on. Return : Return transposed matrix Wh 3 min read
- Python | Numpy matrix.reshape() With the help of Numpy matrix.reshape() method, we are able to reshape the shape of the given matrix. Remember all elements should be covered after reshaping the given matrix. Syntax : matrix.reshape(shape) Return: new reshaped matrix Example #1 : In the given example we are able to reshape the give 1 min read
- numpy.trunc() in Python The numpy.trunc() is a mathematical function that returns the truncated value of the elements of array. The trunc of the scalar x is the nearest integer i which, closer to zero than x. This simply means that, the fractional part of the signed number x is discarded by this function. Syntax : numpy.tr 2 min read
- numpy.asmatrix() in Python numpy.asmatrix(data, dtype = None) Returns a matrix by interpreting the input as a matrix. Parameters : data : array-like input data dtype : Data type of returned array Returns : Interprets the input as a matrix # Python Programming illustrating # numpy.asmatrix import numpy as geek # array-like inp 1 min read
- numpy.rint() in Python The numpy.rint() is a mathematical function that rounds elements of the array to the nearest integer. Syntax : numpy.rint(x[, out]) = ufunc ‘rint’) Parameters : array : [array_like] Input array. Return : An array with all array elements being rounded off, having same type and shape as input. Code #1 2 min read