Challenge: Implementing Benchmarking
Swipe to start coding
Let's practice benchmarking by comparing two approaches to squaring the elements of a NumPy array. The first approach, the slower one, uses a for
loop to square each element individually, while the second approach leverages vectorization. Don't worry if this concept sounds unfamiliar—we'll discuss it later in the course.
Your task for now is the following:
- Define two functions:
- The first, named
square_array_slow
, should take a single parameterarray
; - The second, named
square_array_fast
, should also take the same parameter.
- The first, named
- Decorate both functions with the
timeit_decorator
and setnumber
to100
.
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Awesome!
Completion rate improved to 7.69
Challenge: Implementing Benchmarking
Stryg for at vise menuen
Swipe to start coding
Let's practice benchmarking by comparing two approaches to squaring the elements of a NumPy array. The first approach, the slower one, uses a for
loop to square each element individually, while the second approach leverages vectorization. Don't worry if this concept sounds unfamiliar—we'll discuss it later in the course.
Your task for now is the following:
- Define two functions:
- The first, named
square_array_slow
, should take a single parameterarray
; - The second, named
square_array_fast
, should also take the same parameter.
- The first, named
- Decorate both functions with the
timeit_decorator
and setnumber
to100
.
Løsning
Tak for dine kommentarer!
Awesome!
Completion rate improved to 7.69single