python科学计算——numpy - webdancer's Blog


webdancer posted @ 2014年1月16日 03:22 in 未分类 with tags python , 2727 阅读

numpy是python进行科学计算的一个基础包,它的核心功能是提供ndarray对象,一个实现了n维数组的对象,与python自带的list相比,数组大小初始化时候确定,而且是单一类型(当然也可以使用 对象,这样也能包含多种对象),速度更快,大多数科学计算的程序可能都是基于numpy的。


  • vectorization:说的是可以不适用for,而像线性代数里面提供的操作一样进行计算;
  • broadcasting:指的是对于element-by-element的计算,可以自动进行;


Data type Description
bool_ Boolean (True or False) stored as a byte
int_ Default integer type (same as C long; normally either int64 or int32)
intc Identical to C int (normally int32 or int64)
intp Integer used for indexing (same as C ssize_t; normally either int32 or int64)
int8 Byte (-128 to 127)
int16 Integer (-32768 to 32767)
int32 Integer (-2147483648 to 2147483647)
int64 Integer (-9223372036854775808 to 9223372036854775807)
uint8 Unsigned integer (0 to 255)
uint16 Unsigned integer (0 to 65535)
uint32 Unsigned integer (0 to 4294967295)
uint64 Unsigned integer (0 to 18446744073709551615)
float_ Shorthand for float64.
float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa
float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa
float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa
complex_ Shorthand for complex128.
complex64 Complex number, represented by two 32-bit floats (real and imaginary components)
complex128 Complex number, represented by two 64-bit floats (real and imaginary components)


  1. Conversion from other Python structures (e.g., lists, tuples)
  2. Intrinsic numpy array array creation objects (e.g., arange, ones, zeros, etc.)
  3. Reading arrays from disk, either from standard or custom formats: genfromtxt
  4. Creating arrays from raw bytes through the use of strings or buffers
  5. Use of special library functions (e.g., random)


import numpy as np

x = np.arange(10)

x[0]  ##从零开始索引,返回0

x.shape = (2,5)

x[1,2] ##这是与python的list,tuple不同的地方,支持多维的索引,返回7



x[2:5] #与python的list一样,支持切片操作;


>>> a = np.array([1.0, 2.0, 3.0])
>>> b = 2.0
>>> a * b
array([ 2.,  4.,  6.])

When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when

  1. they are equal, or
  2. one of them is 1


memen 说:
2017年9月20日 03:29

thanks, <a href="" rel="dofollow">trans tv streaming</a> very useful information i will try it directly. Once again I thank you :) <a href="" rel="dofollow">streaming trans tv</a>

memen 说:
2017年9月20日 03:30

thanks, trans tv streaming very useful information i will try it directly. Once again I thank you :) streaming trans tv

Incredimail Customer 说:
2020年8月03日 18:57

One of the finest email services is now offers best resolution for their email clients. “Yes” you heard this right Incredimail is now offering quick assistance. Get easy customer care solutions with email professional's team and surely get hassle free troubleshooting email assistance within sort time to feel an extra ordinary email service.

Comcast Email Suppor 说:
2020年8月03日 18:59

First email solution offers for millions of clients, Get professional’s advice to solve numerous email troubles without extra wait cause Toll-free facility is really easy to reach and comes up with hassle free connectivity and solve clients problems with no wait. If you want to know more about the services please visit our webpage to explore more: – Comcast Email Support

登录 *

loading captcha image...
or Ctrl+Enter
Host by | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee