srush / Tensor-Puzzles

Solve puzzles. Improve your pytorch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Looking for additional instructions

pengzhangzhi opened this issue · comments

commented

A sincerely Thank you to srush for such an amazing exercises. I have questions when dealing with the following puzzles. I am wondering if there are more cues to support me complete them.

## Puzzle 2 - sum

Compute [sum](https://numpy.org/doc/stable/reference/generated/numpy.sum.html) - the sum of a vector.

## Puzzle 7 - cumsum

Compute [cumsum](https://numpy.org/doc/stable/reference/generated/numpy.cumsum.html) - the cumulative sum.


## Puzzle 12 - compress

Compute [compress](https://numpy.org/doc/stable/reference/generated/numpy.compress.html) - keep only masked entries (left-aligned).

def compress(g: TT["i", bool], v: TT["i"], i:int) -> TT["i"]:
   return torch.tensor([v[j] if g[i] else None for j in range(i)])


## Puzzle 15 - bincount

Compute [bincount](https://numpy.org/doc/stable/reference/generated/numpy.bincount.html) - count number of times an entry was seen.

For Puzzle 2 and 7 my recommendation would be to try to come up with a special vector or matrix that can compute the necessary output values. Then it just becomes a matrix multiplication.

For puzzle 15, I would think about one-hot vectors and how they can be used.

commented

Thanks. your instructions are very insightful!