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?
jl66Asked:
Who is Participating?
 
MajorBigDealConnect With a Mentor Commented:
np.insert(an_data,3,1,axis=1)
0
 
jl66Author Commented:
Big help.
0
 
MajorBigDealCommented:
8^)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.