Scalars, Vectors and Matrices in Python

دوره: یادگیری عمیق با TensorFlow / فصل: Appendix Linear Algebra Fundamentals / درس 4

Scalars, Vectors and Matrices in Python

توضیح مختصر

  • زمان مطالعه 0 دقیقه
  • سطح خیلی سخت

دانلود اپلیکیشن «زوم»

این درس را می‌توانید به بهترین شکل و با امکانات عالی در اپلیکیشن «زوم» بخوانید

دانلود اپلیکیشن «زوم»

فایل ویدیویی

برای دسترسی به این محتوا بایستی اپلیکیشن زبانشناس را نصب کنید.

متن انگلیسی درس

Pay after we explore the geometry of linear algebra it is time for yet another point of view the programming

one if you want to get into data science that’s going to be the context in which you will mean linear


So let’s open a Jupiter notebook and see how we can code a matrix a vector and a scalar.

The simplest and most flexible way to work with scalars vectors and matrices in Python is by using arrays.

Moreover we’ll use the number pi functionalities as they are optimized for such operations.

While important number pi as N P OK let’s start by declaring a scalar in Python in many other languages

an integer or a float are doing the job.

So s equals 5.

We’ll do time for something more sophisticated.

How would we declare a vector.

Say we are looking at the same vector as before.

Five minus two and four.

Let’s declare a new variable v equal to any array of five minus two and four.

Note that there are round brackets for the N P array method and square brackets for the vector itself.

Printing V we would see that it contains the three values we wanted.


We have created a vector by default.

V is a row vector


Let’s create a matrix and equals an array of round brackets.

Now if you think about it this matrix actually contains two vectors this one and that one in fact that

is how we would go about declaring it square brackets 5 12 6.

Close the brackets comma square brackets minus 3 0.

14 close all brackets.

Here as you can see we have a matrix exactly as we wanted.

These tasks are quite simple but please feel free to practice later on.

However there are several important programming considerations we need to make.

We will focus on them now as they are paramount for coding.

First data types.

If we write type brackets and then a variable we would obtain the data type of that variable type s

so s is int or an integer.

V and M R and D arrays.

And the array stands for an end dimensional array.

More specifically the vector V is a one dimensional array while the matrix M is a two dimensional array.

In general we can have n dimensional arrays which we will talk about later on.

All right.

Finally if I want to be consistent with the others I can actually declare it as an array to s underscore

array equals P array of five checking its data type again.

We will see it is an array.

And that’s another way you can create a scalar in Python for all practical purposes in Python and within

PI integers or floats and arrays with one element behave in the same way regarding linear algebraic


All right what about the shapes of the variables.

There is a method called Shape which we can apply to our objects to check their dimensionality or shape

em dot shape returns two by three.

And that’s also the expected result as we’re dealing with a two by three Matrix V dot shape returns

3 comma.

This is something which you are likely to see in some programming languages but not all.

It is basically indicating that in the memory of the computer this object has three elements the elements

are stored in order though depending on our needs we can use the reshape method to create a row or column

vector v dot reshape and the form we want.

There are two possibilities.

One three and three.

One the first gives us a row vector.

The second column one

finally we can check the shape of s we get an error as I N T objects don’t have shape.

Trying the same method on X array.

We simply have parentheses.

That’s because a scalar is a zero dimensional object thus it has no shape.

Precisely like the point we discussed in the previous lesson.


That’s more or less how we can declare and think about matrices vectors and scalars and Python and the

next lectures.

We will explore new concepts and practice them with code.

Thanks for watching.

مشارکت کنندگان در این صفحه

تا کنون فردی در بازسازی این صفحه مشارکت نداشته است.

🖊 شما نیز می‌توانید برای مشارکت در ترجمه‌ی این صفحه یا اصلاح متن انگلیسی، به این لینک مراجعه بفرمایید.