create a numpy array with a variable

Question:

I have an variable i_k from I[0]

i_k = I[0]

where

I:

[[0.2]
 [0.3]
 [0.4]
 [0.5]
 [0.6]]

So i_k should be 0.2.

Then when I am trying to create a numpy array

H_k = np.array([[i_k,1]])

instead having [[0.2 1.]], what I have is

[[array([0.2]) 1]]

I am confused. How do I get [[0.2 1.]]? Thanks.

Asked By: Nick X Tsui

||

Answers:

I is a 2D array, so when you say i_k = I[0] you get [0.2]. You can fix this by saying i_k = I[0][0] or i_k = I.flat[0].

Answered By: John Zwinck
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.