rfe*_*and 9 python multidimensional-array fits
我有二维numpy数组形式的三个拟合图像.我想中间组合它们,即生成一个输出数组,其中每个像素是三个输入数组中相同像素的中值.这可以使用imcombine在IRAF上轻松完成.有没有办法在Python上执行此操作而不循环遍历整个数组并获取每个像素的中位数?
Joh*_*yon 13
最简单的方法是:
numpy.median传递axis=0计算沿堆叠维度计算中值.你基本上是计算元素中位数.这是我要做的一个简单的例子:
>>> import numpy
>>> a = numpy.array([[1,2,3],[4,5,6]])
>>> b = numpy.array([[3,4,5],[6,7,8]])
>>> c = numpy.array([[9,10,11],[12,1,2]])
>>> d = numpy.array([a,b,c])
>>> d
array([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 3, 4, 5],
[ 6, 7, 8]],
[[ 9, 10, 11],
[12, 1, 2]]])
>>> d.shape
(3, 2, 3)
>>> numpy.median(d, axis=0)
array([[ 3., 4., 5.],
[ 6., 5., 6.]])
Run Code Online (Sandbox Code Playgroud)