The Wanderer
The Wanderer

Reputation: 3271

Average of a numpy array after applying a function one column at a time

Given:

Expected output: for each data point how many models emitted yes.

out = np.zeros((n, m))
for i, m in enumerate(m_models):
    out[:, i] = m.predict(X)    # Doesn't seem to work
scores = np.mean(out, axis=1)

Upvotes: 0

Views: 73

Answers (1)

Lev Zakharov
Lev Zakharov

Reputation: 2427

You trying assign array of shape n to the column with shape m. Change your out declaration on:

out = np.zeros((m, n))

Or assign predictions to the row:

for i, m in enumerate(m_models):
    out[i, :] = m.predict(X)

Upvotes: 1

Related Questions