Relative Content

Tag Archive for numpy

Linear Regression Using Normal Equation using @ symbol

Write a Python function that performs linear regression using the normal equation. The function should take a matrix X (features) and a vector y (target) as input, and return the coefficients of the linear regression model. Round your answer to four decimal places, -0.0 is a valid result for rounding a very small number.

Use numpy to mask a column containing only zeros (3D array)

I need to achieve basically the solution in this post but for a higher dimensional array. I have an array of shape (100, 24, 29) with dims corresponding to (timepoint x W x H), and I want to delete any columns (from the third dimension) that contain only zeros. I have tried to adapt the answer from the linked post above in this toy example:

Use numpy to mask a row containing only zeros (3D array)

I need to achieve basically the solution in this post but for a higher dimensional array. I have an array of shape (100, 24, 29) with dims corresponding to (timepoint x W x H), and I want to delete any columns (from the third dimension) that contain only zeros. I have tried to adapt the answer from the linked post above in this toy example: