zl程序教程

您现在的位置是:首页 >  Java

当前栏目

环境调试bug【一】

2023-02-18 16:37:21 时间

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循环

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会改变原数组,因此适用于一定需要修改后的结果为值的情况

import numpy as np

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

2) 降维度

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')}")  # 和行一样