2

Say if I have

s=np.zeros((5,5))
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])  #which is an ndarray

s2=[s[ix,1] for ix in range(2,5)],[s[ix2,1] for ix2 in range(2,5)]
([0.0, 0.0, 0.0], [0.0, 0.0, 0.0]) #which is a tuple

How can I make s2 into an array or ndarray? Thank you in advance.

3
  • what is "array"? What shape should the result have? have you tried numpy.concatenate()? Commented Nov 11, 2013 at 3:12
  • 1
    Does numpy.array(s2) not give you what you want? Commented Nov 11, 2013 at 3:12
  • Why is it a tuple? You used a list comprehension to build it. Commented Nov 11, 2013 at 4:15

1 Answer 1

4

Do the obvious, use np.array()

s2 = np.array(s2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.