In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to understand the language of numerical calculation in linux". In daily operation, I believe many people have doubts about how to understand the language of numerical calculation in linux. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubt of "how to understand the language of numerical calculation in linux". Next, please follow the editor to study!
Tuples and arrays
If the numerical calculation is just addition, subtraction, multiplication and division between two scalars, then there is no need for me to waste my breath here. Vectors, matrices and multidimensional arrays are the real protagonists of numerical computation. Therefore, a programming language suitable for numerical computation must have a good way to represent arrays, especially multidimensional arrays. Which way is better? Here's the thing:
The code is as follows:
Int a [m] [n] [k]
It's still like this:
The code is as follows:
Int a [m,n,k]
It doesn't seem to make any difference, but what if you want to get the shape of the array a? Like this:
The code is as follows:
? = a.shape ()
Or go further and want to change the shape of the array a? Like this:
The code is as follows:
A.reshape (?)
In the above code, "?" What on earth should be used instead?
If I were asked to give an answer, I would say: use tuples. There is a concept of tuple in many programming languages, such as Python. Tuples are values separated by commas, with or without parentheses. I think it is more readable with parentheses. For example, (a _ r _ b) is a tuple, and (3p _ 4pr _ 5) is also a tuple. If it is written as [3re4pr 5], it is an array. In Python, it is also called a list. However, Python's list is more powerful than arrays, because arrays can only hold values of the same data type, while lists can hold any object. In general, the length of an array cannot be changed dynamically, while a list can. The term cell array is used in the Octave language to refer to containers that can hold different types of objects. Arrays and matrices in Octave can change the length dynamically. C language arrays do not have the function of dynamically changing the length, but if you use C++, you must use the vector template class.
In my opinion, a good programming language must have the concept of "tuple" and be able to use curly braces, square braces, and parentheses well. On the question of whether there are tuples, many languages do not do well, C language does not have, C++ does not have, Java does not have, C # this language that has a lot of new functions does not have, do not tell me to have Tuple template class to use, that is really not as good as the tuple function built in the language. On the question of whether we can make good use of braces, C language does not do well. You see, whether it initializes the array or initializes the struct, it uses curly braces. Python and JSON do a good job of initializing arrays with square braces and initializing objects or dictionaries with braces. If you add parentheses to indicate tuples, you will get the job done.
Numerical calculation can be carried out for scalar, one-dimensional array, two-dimensional array and n-dimensional array. Arrays can be organized as follows, as shown in the following figure:
The greatest use of tuples is that they can be used to represent the shape of an array. For example, if the shape of an one-dimensional array is (n,), please note that the comma cannot be omitted. The shape of a two-dimensional array (mforce n), the shape of a three-dimensional array (m _ penny n ~ k), and so on. In addition, tuples can be used to index elements in an array. For example:
The code is as follows:
A = [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]; b = a [2, 2, 3, and 3]
Another great use of tuples is to allow a function to return multiple values. C language is ugly in this respect, if a function wants to return multiple values, it can only pass pointers or multiple pointers to the function as parameters, C++ can pass references, C # even more icing on the cake, there is an out keyword to modify the parameters of the function. Microsoft, really, since you can think of out, can't you think of tuples? Common examples, such as the meshgrid () function, can initialize two arrays at the same time, and the peak () function can initialize three arrays at the same time. You see how convenient it is for them to use tuples:
The code is as follows:
(xx, yy) = meshgrid (x, y); (xx, yy, zz) = peak ()
In addition, tuples can be used like this, such as exchanging the values of two variables:
The code is as follows:
(a _ r _ b) = (b _ r _ a)
II. Array initialization
In numerical calculation, the initialization of array is also a very important part. If you write like the C language:
The code is as follows:
Int a = {1,2,3,4,..., 100}
It is estimated that many people are going to scold their mothers. Write like this:
The code is as follows:
For (int item0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.