Osca
Osca

Reputation: 1694

append element to array

I received error while appending element to an array.

array([[ 5,  89,  342,  282,    3,  644, 1254,  634,    4,  711,   58,
        1554,  23,  613,  565,    2,  787,  968,  640,    7,  676,  65,
         346]])

I want to append mean of this array 3 times to this array so if the mean is 10, "10, 10, 10" will be added to the array.

mean = array.mean()
array= array.append(mean, mean, mean)

error message

'numpy.ndarray' object has no attribute 'append'

Where did I do wrong ? thank you

Upvotes: 1

Views: 954

Answers (1)

Mahdi Nazari Ashani
Mahdi Nazari Ashani

Reputation: 391

you should do something like this.

import numpy as np

array = np.array([[ 5,  89,  342,  282,    3,  644, 1254,  634,    4,  711,   58,
        1554,  23,  613,  565,    2,  787,  968,  640,    7,  676,  65,
         346]])

mean = array.mean()

new_array = np.append(array,np.array([mean,mean,mean]))

Upvotes: 1

Related Questions