代码
import numpy as np
# 该代码需要numpy数组最底层维度相同
def parasValue(array):
size = array.shape #获取数组尺寸
value = [] #声明一维列表
for element in array.flat: #将多维numpy数组展开成一维
value_temp = int(element) #对数组中每个数值取整,也可以是其他操作,自己定义
value.append(value_temp) #将处理的各值添加到创建的value列表中
array_list = np.array(value) #将value列表转成numpy数组
array_list = array_list.reshape(size) #将numpy数组reshape到尺寸为size的numpy
return array_list #返回处理好的numpy数组
# Iterate over all indexes ix in x to check the gradient.
it = np.nditer(x, flags=['multi_index'], op_flags=['readwrite'])
while not it.finished:
ix = it.multi_index
# 访问x[ix]
......
it.iternext() # Step to next dimension
其他
np.set_printoptions(suppress=True) #用于禁用numpy使用科学计数法