Skip to content

Instantly share code, notes, and snippets.

@sid137
Created January 11, 2012 19:26
Show Gist options
  • Select an option

  • Save sid137/1596312 to your computer and use it in GitHub Desktop.

Select an option

Save sid137/1596312 to your computer and use it in GitHub Desktop.
#!/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
@sid137
Copy link
Copy Markdown
Author

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