Saturday, 15 May 2010

python - Creat matrix with 2 arrays in numpy -



python - Creat matrix with 2 arrays in numpy -

i want find command in numpy column vector times row vector equals matrix

[1,1,1,1 ] ^t * [ 2,3 ] = [[2,3],[2,3],[2,3],[2,3]]

first, let's define 1-d numpy arrays:

in [5]: 1 = np.array([ 1,1,1,1 ]); 2 = np.array([ 2,3 ])

now, lets multiply them:

in [6]: one[:, np.newaxis] * two[np.newaxis, :] out[6]: array([[2, 3], [2, 3], [2, 3], [2, 3]])

this used numpy's newaxis add together appropriate axes 4x2 output matrix.

python arrays numpy matrix

1 comment:

  1. Matrix and Paging digital PA systems work at their best for large public areas (such as Sydney’s Darling Harbour precinct), transport hubs (train stations, airports, bus terminals etc), casinos and other large public venues. These systems also work for multi-site applications across any IT network near or far.
    http://www.tm-systems.com.au/digitalpa/matrix-and-paging/

    ReplyDelete