首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >环境调试bug【一】

环境调试bug【一】

作者头像
汀丶人工智能
发布2022-12-21 14:44:26
发布2022-12-21 14:44:26
5260
举报
文章被收录于专栏:NLP/KGNLP/KG

1.报错修改`np.bool`---bool

H:\Anaconda3-2020.02\envs\parl\lib\site-packages\paddle\fluid\framework.py:541:

DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.

2.矩阵维度降维:action

输入状态和输出动作维度问题

 3.Python数组操作将一维数组变成二维数组

3.1 方法一:for循环

代码语言:javascript
复制
records = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
result = []
for y in range(0, 4):
    for x in range(0, 3):
        if x == 0:
            result.append([])
        result[y].append(records[x + y * 3])
print(result)

3.2 第二种方法,numpy

1) 升维度

利用函数reshape或者是resize

使用reshape的时候需要注意reshape的结果不改变,因此适用于还要用到原数组的情况

使用resize会改变原数组,因此适用于一定需要修改后的结果为值的情况

代码语言:javascript
复制
import numpy as np

x = np.arange(20)  # 生成数组
print(x)
result = x.reshape((4, 5))  # 将一维数组变成4行5列  原数组不会被修改或者覆盖
x.resize((2, 10))  # 覆盖原来的数据将新的结果给原来的数组
print(x)

2) 降维度

代码语言:javascript
复制
import numpy as np

arr = np.arange(10)
arr.resize((2, 5))
print(arr)
print(f"维度交换:\n{arr.swapaxes(1, 0)}")
print(f"C{arr.flatten('C')}")  # 默认C  一行为主
print(f"\nF:{arr.flatten('F')}")  # 以列为主
print(f"\nA:{arr.flatten('A')}")  # 和行一样
print(f"\nK:{arr.flatten('K')}")  # 和行一样
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-06-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1.报错修改`np.bool`---bool
  • 2.矩阵维度降维:action
  •  3.Python数组操作将一维数组变成二维数组
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档