简体   繁体   中英

Calculating 3D pixel variance from 4D array

Let there be some 4D array [x,y,z,k] comprised of k 3D images [x,y,z]. Is there any way to calculate the variance of each individual pixel in 3D from the 4D array?

Eg I have a 10x10x10x5 array and would like to return a 10x10x10 variance array; the variance is calculated for each pixel (or voxel, really) along k

If this doesn't make sense, let me know and I'll try explaining better.

Currently, my code is:

tensors = []
while error > threshold:
    for _ in range(5): #arbitrary
        new_tensor = foo(bar) #always returns array of same size
        tensors.append(new_tensor)

tensors = np.stack(tensors, axis = 3)
#tensors.shape

And I would like the calculate a variance array for tensors

如果您使用的是numpy,则有一种简单的方法:

variance = tensors.var(axis=3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM