简体   繁体   中英

Getting mean of 2D array

I have a vector representation of n = 1000 images, where each image is represented as 2048 numbers. So I have a numpy array with a shape of (1000, 2048) that I need to find the mean of in a 2048-d vector. If I run this function:

def get_means(f_embeddings):
    means = []
    for embedding in f_embeddings:
        means.append(np.mean(embedding))
    return np.array(means)

I get an ndarray of shape (1000,). How do I loop loop over the array correctly to have a 2048-d vector of means from the original array?

Try:

np.mean(f_embeddings, axis=0)

which should do it without the loop.

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