1. ndarray對(duì)象
ndarray是numpy中的一個(gè)N維數(shù)組對(duì)象,可以進(jìn)行矢量算術(shù)運(yùn)算,它是一個(gè)通用的同構(gòu)數(shù)據(jù)多維容器,即其中的所有元素必須是相同類型的。
可以使用array函數(shù)創(chuàng)建數(shù)組,每個(gè)數(shù)組都有一個(gè)shape(一個(gè)表示各維度大小的元組)和一個(gè)dtype(一個(gè)用于說明數(shù)組數(shù)據(jù)類型的對(duì)象)。


使用zeros和ones函數(shù)可以分別創(chuàng)建數(shù)據(jù)全0或全1的數(shù)組。
numpy.ones(shape, dtype=None,order='C'):其中shape表示返回?cái)?shù)組的形狀;dtype表示數(shù)組數(shù)據(jù)的類型,默認(rèn)為float64;order可以取'C'或'F',表示是否在內(nèi)存中用C或者Fortran形式以連續(xù)順序(row- or column-wise)存放多維數(shù)據(jù)。

2. matrix對(duì)象
numpy庫提供了matrix類,使用matrix類創(chuàng)建的是matrix對(duì)象。matrix對(duì)象是繼承ndarray而來,因此它們和ndarray有相同的屬性和方法。但是它們之間有六個(gè)重要的區(qū)別,使用時(shí)一定要注意:
1) Matrix objects can be created using a string notation to allow Matlab-style syntax where spaces separate columns and semicolons (‘;’) separate rows.
2) Matrix objects are always two-dimensional. This has far-reaching implications, in that m.ravel() is still two-dimensional (with a 1 in the first dimension) and item ? ? ? ? ? selection returns two-dimensional objects so that sequence behavior is fundamentally different than arrays.
3) Matrix objects over-ride multiplication to be matrix-multiplication.Make sure you understand this for functions that you may want to receive matrices. ? ? ? ? ? Especially in light of the fact that asanyarray(m) returns a matrix when m is a matrix.
4) Matrix objects over-ride power to be matrix raised to a power. The same warning about using power inside a function that uses asanyarray(...) to get an array ? ? ? ? ? ? ? object holds for this fact.
5) The default __array_priority__ of matrix objects is 10.0, and therefore mixed operations with ndarrays always produce matrices.
6) Matrices have special attributes which make calculations easier. These are

使用numpy.matrix可以創(chuàng)建一個(gè)矩陣對(duì)象,numpy.mat是它的縮寫。它可以根據(jù)其他matrixs,字符串,或者其他可以轉(zhuǎn)化為ndarray的數(shù)據(jù)創(chuàng)建新的矩陣對(duì)象。
