Click4Ai

499.

Hard

Neural Network Pruning

=======================

Neural network pruning is a technique used to reduce the number of parameters in a neural network while preserving its accuracy. This is essential for deploying models on devices with limited memory or computational resources. In this problem, you will implement a simple neural network pruning technique using weight magnitude pruning.

Example:

Suppose we have a neural network with weights in the range [-1, 1]. We can prune the model by removing weights with magnitude less than a certain threshold.

Constraints:

  • The input is a 2D array of weights with shape (num_layers, num_weights).
  • The output should be a 2D array of pruned weights with shape (num_layers, num_weights).
  • Use NumPy's `where` function to select the weights to prune.
  • Implement a function that takes the input weights and returns the pruned weights.
  • Test Cases

    Test Case 1
    Input: [[0.5, 0.2], [0.1, 0.8]]
    Expected: [[0.5, 0], [0, 0.8]]
    Test Case 2
    Input: [[-1, 1], [0.5, 0.2]]
    Expected: [-1, 0]
    + 3 hidden test cases