Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,38 @@
a=((1, 1, 1, 1), # matrix A #
(2, 4, 8, 16),
(3, 9, 27, 81),
(4, 16, 64, 256))
b=(( 4 , -3 , 4/3., -1/4. ), # matrix B #
(-13/3., 19/4., -7/3., 11/24.),
( 3/2., -2. , 7/6., -1/4. ),
( -1/6., 1/4., -1/6., 1/24.))
def MatrixMul( mtx_a, mtx_b):
tpos_b = zip( *mtx_b)
rtn = [[ sum( ea*eb for ea,eb in zip(a,b)) for b in tpos_b] for a in mtx_a]
return rtn
v = MatrixMul( a, b )
print 'v = ('
for r in v:
print '[',
for val in r:
print '%8.2f '%val,
print ']'
print ')'
u = MatrixMul(b,a)
print 'u = '
for r in u:
print '[',
for val in r:
print '%8.2f '%val,
print ']'
print ')'

View file

@ -0,0 +1,10 @@
from operator import mul
def matrixMul(m1, m2):
return map(
lambda row:
map(
lambda *column:
sum(map(mul, row, column)),
*m2),
m1)

View file

@ -0,0 +1,2 @@
def mm(A, B):
return [[sum(x * B[i][col] for i,x in enumerate(row)) for col in range(len(B[0]))] for row in A]

View file

@ -0,0 +1,4 @@
import numpy as np
np.dot(a,b)
#or if a is an array
a.dot(b)