Premium problem99. Multinomial Rows

Hard Locked

Given a 2-D array X and integer n, return the rows of X that:

  • contain only integers
  • sum to n

These are the rows interpretable as draws from a multinomial with n degrees.

Input

X =
[[1.  0.  3.  8. ]
 [2.  0.  1.  1. ]
 [1.5 2.5 1.  0. ]]
n = 4

Output

[[2. 0. 1. 1.]]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)