博客
关于我
nump模块
阅读量:800 次
发布时间:2023-02-17

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

numpy???Python???????????

numpy?Python?????????????????????????????????????????????????TensorFlow?PyTorch?????numpy???????????????????????????

numpy??????

numpy?Python????????????????????????????????????????????numpy???????????????????????????numpy????????Python??????????????????????????

numpy?????

1.1 ????

?numpy?????????????????????????np.array()???

arr = np.array([1, 2, 3])

???????????????????

arr = np.array([[1, 2, 3], [4, 5, 6]])

1.2 ?????????

????????????shape???????

print(arr.shape)  # ???(2, 3)

1.3 ????

numpy???????????????????????????

  • ????????????
print(arr[1, 1])  # ???6
  • ????5????
print(arr[arr > 5])  # ???[6, 7]
  • ???????????
print(arr > 5)  # ???[[False, False, False],               #          [False, False, False],               #          [False, False, True]]

1.4 ??????

numpy?????????????copy()???????

arr = np.array([[1, 2, 3], [4, 5, 6]])arr_copy = arr.copy()arr_copy[0, 0] = 10print(arr_copy)

1.5 ????

?????????hstack()?vstack()?concatenate()?????

  • ??????????
print(np.hstack((arr1, arr2)))  # ???[[1, 2, 3], [4, 5, 6]]
  • ??????????
print(np.vstack((arr1, arr2)))  # ???[[1, 2, 3], [1, 2, 3]]
  • ???????
print(np.concatenate((arr1, arr2), axis=1))  # ???[[1, 2, 3], [4, 5, 6]]print(np.concatenate((arr1, arr2), axis=0))  # ???[[1, 4], [2, 5], [3, 6]]

1.6 ????????

numpy ???????????????

  • ?0?9????
print(np.arange(10))  # ???[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  • ?????
print(np.linspace(0, 20, 5))  # ???[0., 5., 10., 15., 20.]
  • ?????
print(np.logspace(0, 20, 5))  # ???[1., 10., 100., 1000., 10000.]
  • ?????
print(np.zeros((3, 4)))  # ???[[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]
  • ?????
print(np.ones((3, 4)))  # ???[[1., 1., 1.], [1., 1., 1.], [1., 1., 1.]]
  • ?????
print(np.eye(3))  # ???[[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]
  • ?????
print(np.random.rand(4, 4))  # ????????4x4??

????

numpy ????????????????????????????????????????

??? ??
+ ??????????
- ??????????
* ??????????
/ ??????????
% ?????????????
n ???????n??

???

print(arr1 + arr2)  # ????????????????print(arr1 / arr2)  # ????????????????print(arr1 ** 2)   # ??????????????

?????

?????????transpose()?T?????

print(arr.transpose())  # ???????????print(arr.T)  # ??????????

????

??????????????????????np.linalg.inv()?????????

print(np.linalg.inv(arr))  # ?????????

?????

numpy ????????????????????

???? ?? ????
rand(d0, d1, ..., dn) ??[0,1)????????? d0, d1, ..., dn???????
randn(d0, d1, ..., dn) ??????????? ??
randint(low, high, size) ?????? low?????high?????size?????
random_sample([size]) ??[0,1)????? size???????
choice(a, size) ???a????????? a?1????size?????

???

print(np.random.rand(10))  # ???10?[0,1)?????print(np.random.randn(10))  # ???10??????????print(np.random.randint(1, 10, 5))  # ???5?????

?????????????????????????

????

  • ?????????????????????????????
  • ???????????????????
  • ????????????????????????

????????????????numpy???????????????????????????????????numpy???????????

转载地址:http://xwnfk.baihongyu.com/

你可能感兴趣的文章
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node.js 函数是什么样的?
查看>>
Node.js 历史
查看>>
Node.js 在个推的微服务实践:基于容器的一站式命令行工具链
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>
node.js 怎么新建一个站点端口
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
node.js 简易聊天室
查看>>
node.js 配置首页打开页面
查看>>
node.js+react写的一个登录注册 demo测试
查看>>
Node.js中环境变量process.env详解
查看>>
Node.js卸载超详细步骤(附图文讲解)
查看>>
Node.js安装与配置指南:轻松启航您的JavaScript服务器之旅
查看>>
Node.js安装及环境配置之Windows篇
查看>>
Node.js安装和入门 - 2行代码让你能够启动一个Server
查看>>
node.js安装方法
查看>>