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

numpy的学习笔记(五)—— 矩阵和通用函数

2017-12-23 17:14 288 查看
第五章 矩阵和通用函数

1、矩阵

        创建矩阵:A=np.mat('1 2 3; 4 5 6; 7 8 9')

        矩阵转置:B=A.T

        矩阵求逆:B=A.I

        分块矩阵:C=np.bmat("A B; A B")

2、通用函数

        ufunc = np.frompyfunc(ultimate, 1, 1)

        方法:reduce、accumulate、reduceat、outer

        np.add.reduce(a)

        np.add.accumulate(a)

        np.add.reduceat(a, [0, 5, 2, 7])

        np.add.outer(np.arange(3), a)

3、数组除法

        取整数:np.divide(a, b)   a/b

        取浮点数:np.true_divide(a, b)

        向下取浮点数:np.floor_divide(a, b)    a//b

4、模运算

        np.remaider(a, 2)

        np.mod(a, 2)     a%2

        np.fmod(a, 2)    负数取余

5、fibonacci

        F = np.matrix([ [ 1, 1], [1, 0] ])

        (F ** 7)[0, 0]

6、lissajous

        t = np.linspace(-np.pi, np.pi, 201)

        x = np.sin(a*t + np.pi/2)

        y = np.sin(b*t)

7、方波

        for i in range(len(t)):

            f[i] = np.sum(np.sin(k * t[i])/k)

        f = (4 / np.pi) * f

8、锯齿波和三角波

        for i in range(len(t)):

           f[i] = np.sum(np.sin(2*np.pi * k * t[i])/k)

        np.abs(f)

9、位操作和比较

        ^ :bitwise_xor

        &:bitwise_and

        | :bitwise_or

        <<:left_shift

       >>:right_shift

        <:less

        >:more

        ==: equal


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