Skip to content
DeepForgeby svx
All problems
EasyTime Seriests-232

Patch Count

Problem

Compute how many patches can be extracted from a series with a given patch length and stride: (length - patch_length) // stride + 1.

Return 0 when patch_length or stride is not positive, or the series is shorter than one patch.

Hint

Patch-based transformers tokenize a series the way ViT tokenizes an image.

Test cases

case 1
in: [10,4,2]
expected: 4
case 2
in: [10,10,1]
expected: 1
case 3
in: [10,3,3]
expected: 3
case 4
in: [2,5,1]
expected: 0
Starter codePython
def patch_count(length, patch_length, stride):
    # Your code here
    pass

4 test cases · run your code against them in the editor