First, what is a vector?
In mathematics, vectors (also known as Euclidean vectors, geometric vectors and vectors) refer to quantities with magnitude an
First, what is a vector?
In mathematics, vectors (also known as Euclidean vectors, geometric vectors and vectors) refer to quantities with magnitude and direction. It can be imagined as a line segment with an arrow. The arrow indicates the direction of the vector; Line segment length: indicates the size of the vector. Only the magnitude corresponds to the vector, and the quantity without direction is called quantity (called scalar in physics).
The vector here is a one-dimensional array, and it is one of the easiest ways to create a vector with the function of arange:
The arange function can also specify an initial value, an end value and a step size to create a one-dimensional array:
Vectors can also act directly on each element:
Second, create a vector.
What is used above is a method of creating vectors. In fact, any function created by an array can create a vector, for example:
Linspace () function
Introduction: linspace creates a arithmetic progression vector by setting an initial value, an ending value and the number of elements, and specifies whether the ending value is included in the endpoint parameter, which is true by default.
Logspace () function
In linspace, a geometric series is created, the cardinality is specified by the base parameter, and the default cardinality is 10.
0 () function and 1 () function.
These two functions can create all 0s or all 1s n array arrays of specified length or shape, respectively, for example:
Specify data type:
Empty () function
This function can create a ndarray array without any specific values, for example:
Random.randn () function
Randn is a function that generates normal random data in numpy.random
Fromstring () function
Create an array from a string
The array created from the above string is defined as integer 8bit, which is actually the ASCII code of the string.
Fromfunction () function
Creating arrays from functions is a common data analysis method.
You can first define a function to calculate the values of subscripts, and then create an array with fromfunction.
The first parameter of fromfunction is the name of the function that calculates each array element, and the second parameter specifies the shape of the array. Because it supports multidimensional arrays, the second parameter must be a sequence.
For example, I created a 99 multiplication table:
Note that the second parameter in the fromfunction function specifies the subscript of the array, which is passed to the function as an argument by traversing.
There are many python training videos on python Learning Network. Welcome to online learning!