0
arr2=[0]*(x^2) # x is the length of the list data for i in range(x): arr2[i]=data[i].split(',')#data is a list like:['1,2','3,4'] arr2=np.array(arr2) A=np.asmatrix(arr2) print A.I 

This is giving error as setting an array element with a sequence

4
  • 2
    Please give some context about what you're trying to do and give a specific question related to the problem you're having. Commented Jul 3, 2013 at 13:49
  • I need to have a matrix to take out its inverse Commented Jul 3, 2013 at 14:08
  • @abcdxx did you check my answer? Commented Jul 3, 2013 at 14:12
  • @abcdxx You don't need to create the intermediate array to create the matrix, check the answer below... Commented Jul 3, 2013 at 16:44

1 Answer 1

0

Something like this:

>>> data = ['1,2','3,4'] >>> arr2=[ map(float,x.split(',')) for x in data] >>> arr2 = np.asarray(arr2) >>> A = np.asmatrix(arr2) >>> A.I matrix([[-2. , 1. ], [ 1.5, -0.5]]) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.