您的位置:首页 > 编程语言 > Python开发

numpy矩阵

2015-09-08 13:12 567 查看
np.matrix(np.identity(10))
In [20]: cmp(10,2) #
cmp(x,y):
Out[20]: 1


In [21]: cmp(10,22)

Out[21]: -1


In [22]: cmp(10,10)

Out[22]: 0

[/code]
In [3]: import numpy as np


In [4]: a1=np.array([1,2,3],dtype=int)


In [5]: a2=np.array([[1,2,3],[2,3,4]])


In [6]: b1=np.zeros((2,3))

[/code]
In [7]: b1

[code]Out[7]:

array([[ 0.,  0.,  0.],

[ 0.,  0.,  0.]])


In [8]: a2

Out[8]:

array([[1, 2, 3],

[2, 3, 4]])


In [9]: a1

Out[9]: array([1, 2, 3])

[/code]
compile(source, filename, mode[, flags[, dont_inherit]])

[/code]Compile the source into a code or AST object. Code objects can be executed by an exec statement or evaluated by a call to eval().source can either be a Unicode string, a Latin-1 encoded string or an AST object. Refer to the ast module documentation for information on how to work with AST objects.

来源: <https://docs.python.org/2/library/functions.html#cmp>
divmod(a, b)

[/code]Take two (non complex) numbers as arguments and return a pair of numbers consisting of their quotient and remainder when using long division. With mixed operand types, the rules for binary arithmetic operators apply. For plain and long integers, the result is the same as (a // b, a % b). For floating point numbers the result is (q, a % b), where q is usually math.floor(a / b) but may be 1 less than that. In any case q * b + a % b is very close to a, if a % b is non-zero it has the same sign as b, and 0 <= abs(a % b) < abs(b).

来自为知笔记(Wiz)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: