Python matrix, any solution? -


my input(just example):

from numpy import *   x=[['1' '7']  ['1.5' '8']  ['2' '5.5']  ['2' '9']] 

i want make next thing on random matrix:

1. each row calculate:

> example first row:    [1;7]*[1,7] = [[1,  7];      #value * value.transpose                                           [7,  49]]  > example second row:   [1.5;8]*[1.5,8]=  [[2.25, 12];                                                [12,  64]]  >....... 

this simple numpy, because transpose x.t, if x=[1,7] must calculated every row on matrix!

2. want sum in way...

[1+2.25+...         7+12+......  ] [                                ]            [7+12+....          49+64+....   ] 

so result matrix.

any ideas?


edit2:

x=[['1','7']  ['1.5', '8']  ['2', '5.5']  ['2','9']]  y = x[:, :, none] * x[:, none] print y.sum(axis=0) 

i received error:

"list indices must integers, not tuple"

but if x x = numpy.array([[1, 7], [1.5, 8], [2, 5.5], [2, 9]]) it's ok, don't have such input.

how following:

in [1]: import numpy np  in [2]: x=np.array([[1, 7],[1.5, 8],[2, 5.5],[2, 9]])  in [3]: np.sum(np.outer(row,row) row in x) out[3]:  array([[  11.25,   48.  ],        [  48.  ,  224.25]]) 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -