Integers to Binary Matrix
mediumnumpy_manipulationImplement to_binary(x, bits).
Given a 1D array x of non-negative integers, return a (len(x), bits) array
of 0/1 where row i is the binary representation of x[i], most
significant bit first. No for/while loops.
Constraints
- no scipy, sklearn
- no for/while loops
Your solution
Edit to_binary and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Build the bit masks 2**(bits-1) … 2**0, then test each value against them with broadcasting.