import numpy as np
from scipy import signal
d0 = np.random.random_integers(10, 12, (5,5))
d1 = np.random.random_integers(1, 3, (5,5))
d2 = np.random.random_integers(4, 6, (5,5))
d3 = np.random.random_integers(7, 9, (5,5))
d4 = np.random.random_integers(1, 3, (5,5))
d5 = np.random.random_integers(13, 15, (5,5))
data = np.array([d0,d1,d2,d3,d4,d5])
data = data.reshape(6,25)
data = data.T
想按列计算最小值:
minimas =[]
for x in data:
minima = (signal.argrelmin(x, axis=0))
minimas.append(x[minima])
希望以原始数据的形式存储结果。你知道吗
print np.array(minimas).reshape([5,5])
但是
ValueError: total size of new array must be unchanged
难道不能将结果存储为大数组的元组吗? 如果有更有效的方法解决这个问题,我将不胜感激。你知道吗
您需要将每个项目转换为列表,然后使用列表切片可以索引您需要的任何值。你知道吗
minimas
是25个数组的列表(每个形状(2,)
)。np.array(minimas)
具有形状(25,2)
。你知道吗工作。你知道吗
您可以使用
dtype=object
将minimas
打包到一个数组中:如果
minimas
中的数组大小不同,那么该数组将自动具有类型object
。你知道吗产生
可以是
reshape(5,5)
。你知道吗如果
minimas
中的数组长度相同,则np.array(minimas)
生成一个最终大小为2维的数组。这就是为什么我必须初始化所需类型的minarray
数组,并在其中插入minimas
。这是numpy
中一个模糊的部分,我是从回答其他问题中学到的。你知道吗相关问题 更多 >
编程相关推荐