LESSON 25 OF 52 · CHAPTER 04
Vectors
Numeric vector literals, len, indexing and numeric operations
01-vectors.srp
bind values = [1.0, 2.0, 3.0, 4.0];
print(values, len(values), values[0]);
var weights = [0.2, 0.3, 0.5];
bind snapshot = weights;
weights = scale(weights, 2.0);
print(snapshot);
print(weights);
print(sum(values), mean(values));
print(dot(values, [2.0, -1.0, 0.5, 2.0]));
print(mse([1.0, 2.0], [1.0, 4.0]));
print(clamp([-2.0, 0.5, 3.0], 0.0, 1.0));
print(fill(1.5, 3));
stdout
[1.0, 2.0, 3.0, 4.0] 4 1.0
[0.2, 0.3, 0.5]
[0.4, 0.6, 1.0]
10.0 2.5
9.5
2.0
[0.0, 0.5, 1.0]
[1.5, 1.5, 1.5]
Write what you expect this program to print. Check prediction for a line-level hint without revealing the answer, or reveal the verified output when ready. This checks displayed text only; it does not run Scarp or save your input.
UNDERSTAND THE CODE
Explanation & practice
What this example teaches
Numeric vector literals, len, indexing and numeric operations
Expected behavior
Printed vector values and computed aggregates
Practice: Read the source before looking at the output. Predict the values and their order, then use the pinned compiler to execute this lesson and compare the exact fixture. Identify which operation produces the result.
वेक्टर और संख्यात्मक फ़ंक्शन
len(values) लंबाई और values[0] पहला मान देता है। scale, sum, mean, dot, mse, clamp और fill संख्यात्मक फ़ंक्शन हैं। स्केल किया गया नया weights पुराने snapshot से अलग है।
आउटपुट: sum(values) = 10.0, mean(values) = 2.5। पूरा आठ-पंक्तियों वाला आउटपुट मूल फ़ाइल से मिलाएँ।
अभ्यास: पुराना snapshot [0.2, 0.3, 0.5] क्यों बना रहता है?
Explanations are sourced from the project's English chapter guide and हिन्दी अध्याय. The Scarp program and output are unchanged.
SOURCE-BACKED SELF-CHECK · स्रोत-आधारित अभ्यास
Quick checkpoint / त्वरित अभ्यास
What mean does mean(values) print for [1.0, 2.0, 3.0, 4.0]?[1.0, 2.0, 3.0, 4.0] के लिए mean(values) क्या प्रिंट करता है?
Reveal the source-backed answer / सही उत्तर देखें
2.5 — The four values sum to 10.0. Dividing by their count (4) gives a mean of 2.5.2.5 — चार संख्याओं का योग 10.0 है। 10.0 को 4 से भाग देने पर औसत 2.5 मिलता है।
This question checks understanding of a recorded compiler output. It does not run Scarp in the browser. यह प्रश्न सत्यापित आउटपुट पर आधारित है; ब्राउज़र में Scarp नहीं चलता।
LEARNING PROGRESS
Keep your place
Mark this lesson complete when you are ready.
Only saved in this browser. No account or tracking.
TRY IT LOCALLY
Verify, then execute
Use the pinned compiler from the course root. Keep any imported _support files next to the source.
scarp verify examples/04-collections/01-vectors.srp
scarp exec examples/04-collections/01-vectors.srpThe website does not run code. Read the CLI guide ↗
Pinned compiler: Scarp v0.0.6-alpha.3
· ceff07d9014f. No simulated output.