Extracting a column out

Question:

I have a list of array of the form.

params = [[array([7.30946927, 2.40445369])],
 [array([7.30886254, 2.40241312])],
 [array([7.21275251, 2.09358208])],
 [array([7.61757898, 0.15745312])],
 [array([7.76890152, 2.70100186])],
 [array([7.82943027, 2.39066977])],
 [array([7.20117715, 2.05259557])],
 [array([7.21455828, 2.09081677])],
 [array([7.46129784, 1.9455824 ])]]

I want to extract out the first element (7.3, 7.3 etc) into a new array that I want to use for plotting.

I have managed to convert this list into an array.
PN = np.array(fit_params)

But how do I extract the first column? PN[:,0] doesn’t work? I want an array of all the first column elements into one variable.

Asked By: Khushal

||

Answers:

values = []
for i in params :
    values.append(i[0][0])

print(values)
Answered By: Yash Upadhyaya
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.