博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Numpy数值计算基础
阅读量:7232 次
发布时间:2019-06-29

本文共 2257 字,大约阅读时间需要 7 分钟。

1 # -*- coding: utf-8 -*- 2  3 ############################################################################### 4 #######################            正文代码             ####################### 5 ############################################################################### 6  7 # 代码 2-30 8 import numpy as np  #导入NumPy库 9 matr1 = np.mat("1 2 3;4 5 6;7 8 9") #使用分号隔开数据10 print('创建的矩阵为:',matr1)11 12 matr2 = np.matrix([[123],[456],[789]])13 print('创建的矩阵为:',matr2)14 15 16 # 代码 2-3117 arr1 = np.eye(3)18 print('创建的数组1为:',arr1)19 20 arr2 = 3*arr121 print('创建的数组2为:',arr2)22 23 print('创建的矩阵为:',np.bmat("arr1 arr2; arr1 arr2"))24 25 26 # 代码 2-3227 matr1 = np.mat("1 2 3;4 5 6;7 8 9")  #创建矩阵28 print('创建的矩阵为:',matr1)29 30 matr2 = matr1*3  #矩阵与数相乘31 print('创建的矩阵为:',matr2)32 print('矩阵相加结果为:',matr1+matr2)  #矩阵相加33 print('矩阵相减结果为:',matr1-matr2)  #矩阵相减34 print('矩阵相乘结果为:',matr1*matr2)  #矩阵相乘35 print('矩阵对应元素相乘结果为:',np.multiply(matr1,matr2))36 37 # 代码 2-3338 '''39 print('矩阵转置结果为:',matr1.T)  #转置40 print('矩阵共轭转置结果为:',matr1.H)  #共轭转置(实数的共轭就是其本身)41 print('矩阵的逆矩阵结果为:',matr1.I)  #逆矩阵42 print('矩阵的二维数组结果为:',matr1.A)  #返回二维数组的视图43 '''44 # 代码 2-3445 x = np.array([1,2,3])46 y = np.array([4,5,6])47 print('数组相加结果为:',x + y)  #数组相加48 print('数组相减结果为:',x - y)  #数组相减49 print('数组相乘结果为:',x * y)  #数组相乘50 print('数组相除结果为:',x / y)  #数组相除51 print('数组幂运算结果为:',x ** y)  #数组幂运算52 53 # 代码 2-3554 x = np.array([1,3,5])55 y = np.array([2,3,4])56 print('数组比较结果为:',x < y)57 print('数组比较结果为:',x > y)58 print('数组比较结果为:',x == y)59 print('数组比较结果为:',x >= y)60 print('数组比较结果为:',x <= y)61 print('数组比较结果为:',x != y)62 63 # 代码 2-3664 print('数组逻辑运算结果为:',np.all(x == y))  #np.all()表示逻辑and65 print('数组逻辑运算结果为:',np.any(x == y))  #np.any()表示逻辑or66 67 # 代码 2-3768 arr1 = np.array([[0,0,0],[1,1,1],[2,2,2],[3,3,3]])69 print('创建的数组1为:',arr1)70 print('数组1的shape为:',arr1.shape)71 arr2 = np.array([1,2,3])72 print('创建的数组2为:',arr2)73 print('数组2的shape为:',arr2.shape)74 print('数组相加结果为:',arr1 + arr2)75 76 # 代码 2-3877 arr1 = np.array([[0,0,0],[1,1,1],[2,2,2],[3,3,3]])78 print('创建的数组1为:',arr1)79 print('数组1的shape为:',arr1.shape)80 81 arr2 = np.array([1,2,3,4]).reshape((4,1))82 print('创建的数组2为:',arr2)83 print('数组2的shape为:',arr2.shape)84 print('数组相加结果为:',arr1 + arr2)

 

转载于:https://www.cnblogs.com/779084229yyt/p/9442715.html

你可能感兴趣的文章
Spreading the Wealth uva 11300
查看>>
Eclipse 报java.lang.UnsupportedClassVersionError: ("yourclass") bad major version at offset=6
查看>>
快读快输板子
查看>>
vue中父组件给子组件额外添加参数
查看>>
分片上传
查看>>
网络编程初识和socket套接字
查看>>
什么是构造函数?它和普通函数的区别?
查看>>
mysql中key 、primary key 、unique key 与index区别
查看>>
zabbix使用企业微信发送告警信息
查看>>
zabbix4.0离线快速编译安装(编译安装方法)
查看>>
[Java开发之路](7)RandomAccessFile类详解
查看>>
Linux中的tty与pts
查看>>
Java socket示例(demo)TCP/IP
查看>>
error: WatchKit App doesn't contain any WatchKit Extensions whose WKAppBundleIdentifier matches
查看>>
计算UITextView的滑动高度
查看>>
AngularJs的UI组件ui-Bootstrap分享(四)——Datepicker Popup
查看>>
Java虚拟机------垃圾收集器
查看>>
UVA 1376 Animal Run 最短路
查看>>
oracle12c之 单机12.1.0.1打补丁
查看>>
封装了集中常用的文件读的方法
查看>>