Mockbit/#89
MLmediumData processing~10m

Sinusoidal Positional Encoding Matrix

Problem

Implement sinusoidal positional encoding using only NumPy. Generate position encodings where even dimensions use sine and odd dimensions use cosine, with frequencies based on 10000^(2i/d_model).

Examples

Example 1

Input: seq_len=2, d_model=4
Output: [[0.0, 1.0, 0.0, 1.0], [0.84147, 0.5403, 0.01, 0.99995]]

Position 0 has sine/cosine of 0, position 1 uses different frequencies for each dimension pair.

Constraints
  • NumPy only (import numpy as np)
  • Function must be named solution
Reference solution

Reference solution available after you attempt the question.

Ready to solve it?

Start a session on Mockbit #89. You'll get graded with specific critique when you submit.

Related ML questions
← Back homemockbit.io/q/89
PrivacyTerms© 2026 Mockbit