Create a gist now

Instantly share code, notes, and snippets.

@sid137 /gk.py
Created Jan 11, 2012

What would you like to do?
#!/usr/bin/python
import numpy as np
a = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
b = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
A = np.array(a)
B = np.array(b)
# i
colsA = A.shape[0]
# j
rowsA = A.shape[1]
# k
colsB = B.shape[0]
# j
rowsB = B.shape[1]
C = np.zeros((colsA, rowsA, colsB))
for i in range(colsA):
for j in range(rowsA):
for k in range(colsB):
C[i,j,k] = A[i,j] * B[k, j]
print C
Owner

sid137 commented Jan 11, 2012

:~ $ ./gk.py
[[[ 1. 2. 3.]
[ 1. 2. 3.]
[ 1. 2. 3.]]

[[ 2. 4. 6.]
[ 2. 4. 6.]
[ 2. 4. 6.]]

[[ 3. 6. 9.]
[ 3. 6. 9.]
[ 3. 6. 9.]]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment