NumPy Introduction

原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/12243889.html

Introduction

NumPy is the fundamental package for scientific computing with Python. It contains among other things:

  • a powerful N-dimensional array object
  • sophisticated (broadcasting) functions
  • tools for integrating C/C++ and Fortran code
  • useful linear algebra, Fourier transform, and random number capabilities

Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

Why NumPy is so important?

One of the reasons NumPy is so important for numerical computations in Python is because it is designed for efficiency on large arrays of data.

There are a number of reasons for this:

  • NumPy internally stores data in a contiguous block of memory, independent of other built-in Python objects. NumPy’s library of algorithms written in the C language can operate on this memory without any type checking or other overhead. NumPy arrays also use much less memory than built-in Python sequences.
  • NumPy operations perform complex computations on entire arrays without the need for Python for loops.

e.g.

Conclusion

NumPy-based algorithms are generally 10 to 100 times faster (or more) than their pure Python counterparts and use significantly less memory.

Reference

Python for Data Analysis Second Edition

https://numpy.org/

原文地址:https://www.cnblogs.com/agilestyle/p/12243889.html