Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Vectors and Their Operations | Section
Mastering Linear Algebra Fundamentals

bookVectors and Their Operations

メニューを表示するにはスワイプしてください

Understanding vectors is the first step to mastering linear algebra. A vector is a mathematical object that has both magnitude (size) and direction. Vectors are often written as an ordered list of numbers, like [2,3][2, 3] or [1,4,5][1, -4, 5]. The number of elements in a vector is called its dimension, for example, [2,3][2, 3] is a 2-dimensional vector, while [1,4,5][1, -4, 5] is 3-dimensional.

Vectors appear everywhere in the real world. You can think of a vector as representing a force pushing an object, a velocity describing movement through space, or a position on a map. In computer graphics, vectors describe points and directions; in physics, they describe forces and velocities. In data science, they represent data points with many features.

12345678910111213141516171819
# Creating vectors in Python using lists vector_a = [2, 3] vector_b = [4, 1] # Vector addition vector_sum = [a + b for a, b in zip(vector_a, vector_b)] # Vector subtraction vector_diff = [a - b for a, b in zip(vector_a, vector_b)] # Scalar multiplication (multiply each element by a number) scalar = 3 vector_scaled = [scalar * a for a in vector_a] print("Vector A:", vector_a) print("Vector B:", vector_b) print("A + B:", vector_sum) print("A - B:", vector_diff) print("3 * A:", vector_scaled)
copy

In this code, you create two vectors, vector_a and vector_b, as Python lists. Each list contains two numbers, making them 2-dimensional vectors. To add or subtract vectors, you combine their corresponding elements. This is done using a list comprehension with the zip function, which pairs up the elements from each vector.

For vector addition, [a + b for a, b in zip(vector_a, vector_b)] adds the first elements of vector_a and vector_b to get the first element of the result, and does the same for the second elements. Vector subtraction works the same way, but with subtraction.

Scalar multiplication means multiplying every element of a vector by the same number. In the code, [scalar * a for a in vector_a] multiplies each element of vector_a by 3.

Python lists allow you to represent vectors and perform these operations, but you must handle the arithmetic element by element. This approach helps you see the structure of vector operations, which is essential for understanding more advanced linear algebra topics.

question mark

Which of the following statements about vectors and their operations is correct based on the code and explanations above?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  1
some-alt