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

The need for NumPy arrays

A fundamental question that beginners ask is. Why are arrays necessary for scientific computing at all? Surely, one can perform complex mathematical operations on any abstract data type, such as a list. The answer lies in the numerous properties of arrays that make them significantly more useful. In this section, let's go over a few of these properties to emphasize why something such as the NumPy ndarray object exists at all.

Representing of matrices and vectors

The abstract mathematical concepts of matrices and vectors are central to many scientific problems. Arrays provide a direct semantic link to these concepts. Indeed, whenever a piece of mathematical literature makes reference to a matrix, one can safely think of an array as the software abstraction that represents the matrix. In scientific literature, an expression such as Aij is typically used to denote the element in the i th row and j th column of array A. The corresponding expression in NumPy would simply be A[i,j]. For matrix operations, NumPy arrays also support vectorization (details are addressed in Chapter 3 , Using NumPy Arrays), which speeds up execution greatly. Vectorization makes the code more concise, easier to read, and much more akin to mathematical notation. Like matrices, arrays can be multidimensional too. Every element of an array is addressable through a set of integers called indices, and the process of accessing elements of an array with sets of integers is called indexing. This functionality can indeed be implemented without using arrays, but this would be cumbersome and quite unnecessary.

Efficiency

Efficiency can mean a number of things in software. The term may be used to refer to the speed of execution of a program, its data retrieval and storage performance, its memory overhead (the memory consumed when a program is executing), or its overall throughput. NumPy arrays are better than most other data structures with respect to almost all of these characteristics (with a few exceptions such as pandas, DataFrames, or SciPy's sparse matrices, which we shall deal with in later chapters). Since NumPy arrays are statically typed and homogenous, fast mathematical operations can be implemented in compiled languages (the default implementation uses C and Fortran). Efficiency (the availability of fast algorithms working on homogeneous arrays) makes NumPy popular and important.

Ease of development

The NumPy module is a powerhouse of off-the-shelf functionality for mathematical tasks. It adds greatly to Python's ease of development. The following is a brief summary of what the module contains, most of which we shall explore in this book. A far more detailed treatment of the NumPy module is in the definitive Guide to NumPy, Travis Oliphat. The NumPy API is so flexible that it has been adopted extensively by the scientific Python community as the standard API to build scientific applications. Examples of how this standard is applied across scientific disciplines can be found in The NumPy Array: a structure for efficient numerical computation, Van Der Walt, and others:

主站蜘蛛池模板: 龙南县| 裕民县| 桦甸市| 繁峙县| 新兴县| 阳泉市| 长沙县| 时尚| 繁昌县| 龙川县| 清徐县| 玉环县| 偃师市| 桐梓县| 乡宁县| 东乌珠穆沁旗| 洛川县| 云和县| 漳州市| 青阳县| 邹城市| 台山市| 宁明县| 乐平市| 柞水县| 庆城县| 同心县| 会泽县| 龙州县| 乾安县| 京山县| 灌云县| 手机| 潍坊市| 元阳县| 花垣县| 栾城县| 天峨县| 呼图壁县| 九龙县| 东乡族自治县|