Link to home
Start Free TrialLog in
Avatar of jl66
jl66Flag for United States of America

asked on

How to add a column in an array

Have an array with narray form from import numpy. Want to add a column with a given value. How to do that. For example,

>>> import numpy as np

>>> an_data = np.random.random((8,3))

>>> an_data
array([[ 0.5300833 ,  0.67717517,  0.26438946],
       [ 0.42086719,  0.84103232,  0.49834054],
       [ 0.61089945,  0.55748528,  0.46789543],
       [ 0.70172091,  0.69870567,  0.8568496 ],
       [ 0.11526463,  0.31571104,  0.69761736],
       [ 0.2783778 ,  0.95186246,  0.35573732],
       [ 0.48809306,  0.38034416,  0.04698633],
       [ 0.05396656,  0.49011478,  0.12898373]])
>>> an_data.shape
#(8, 3)

#Want to append a column with a given value, saying 1, ie
array([[ 0.5300833 ,  0.67717517,  0.26438946, 1],
       [ 0.42086719,  0.84103232,  0.49834054, 1],
       [ 0.61089945,  0.55748528,  0.46789543, 1],
       [ 0.70172091,  0.69870567,  0.8568496, 1],
       [ 0.11526463,  0.31571104,  0.69761736, 1],
       [ 0.2783778 ,  0.95186246,  0.35573732, 1],
       [ 0.48809306,  0.38034416,  0.04698633, 1],
       [ 0.05396656,  0.49011478,  0.12898373, 1]])

How to get it?
ASKER CERTIFIED SOLUTION
Avatar of MajorBigDeal
MajorBigDeal
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jl66

ASKER

Big help.