官术网_书友最值得收藏!

NumPy arrays

After going through the installation of NumPy, it's time to have a look at NumPy arrays. NumPy arrays are more efficient than Python lists when it comes to numerical operations. NumPy arrays are, in fact, specialized objects with extensive optimizations. NumPy code requires less explicit loops than equivalent Python code. This is based on vectorization.

If we go back to highschool mathematics, then we should remember the concepts of scalars and vectors. The number 2, for instance, is a scalar. When we add 2 to 2, we are performing scalar addition. We can form a vector out of a group of scalars. In Python programming terms, we will then have a one-dimensional array. This concept can, of course, be extended to higher dimensions. Performing an operation on two arrays, such as addition, can be reduced to a group of scalar operations. In straight Python, we will do that with loops going through each element in the first array and adding it to the corresponding element in the second array. However, this is more verbose than the way it is done in mathematics. In mathematics, we treat the addition of two vectors as a single operation. That's the way NumPy arrays do it too, and there are certain optimizations using low-level C routines, which make these basic operations more efficient. We will cover NumPy arrays in more detail in the following chapter, Chapter 2, NumPy Arrays.

主站蜘蛛池模板: 时尚| 蕲春县| 柘荣县| 中方县| 离岛区| 越西县| 米泉市| 班戈县| 大荔县| 枝江市| 河东区| 衡山县| 阳朔县| 井陉县| 红安县| 富平县| 保亭| 丰城市| 丹东市| 雷波县| 德钦县| 东阿县| 赤城县| 沙洋县| 营山县| 遵义市| 林州市| 防城港市| 常宁市| 澳门| 建平县| 德州市| 汝州市| 东至县| 乌拉特后旗| 抚顺市| 广德县| 宜春市| 密山市| 陆丰市| 安龙县|