just a quick question, if I have a matrix has n rows and m columns, how can I cut off the 4 sides of the matrix and return a new matrix? (the new matrix would have n-2 rows m-2 columns).
Thanks in advance
round_() in Python. The numpy. round_() is a mathematical function that rounds an array to the given number of decimals.
With the help of Numpy matrix. round() method, we are able to round off the values of the given matrix.
Using the NumPy function np. delete() , you can delete any row and column from the NumPy array ndarray . Specify the axis (dimension) and position (row number, column number, etc.). It is also possible to select multiple rows and columns using a slice or a list.
trunc. Return the truncated value of the input, element-wise.
a[1:-1, 1:-1]
A more general answer is:
a[[slice(1, -1) for _ in a.shape]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With