Commit ed9e7f41 by Paul McCarthy 🚵

### Nearly there with numpy prac

parent 27317639
 #!/usr/bin/env python import numpy as np data = np.loadtxt('04_numpy/2d_array.txt', comments='%') colmeans = data.mean(axis=0) msg = ''.join([chr(int(round(m))) for m in colmeans]) print('Column means') print('\n'.join(['{}: {}'.format(i, m) for i, m in enumerate(colmeans)])) print('Secret message:', msg)
 #!/usr/bin/env python import numpy as np import numpy.linalg as npla def concat(*xforms): """Combines the given matrices (returns the dot product).""" result = xforms[0] for i in range(1, len(xforms)): result = np.dot(result, xforms[i]) return result def transform(xform, coord): """Transform the given coordinates with the given affine. """ return np.dot(xform[:3, :3], coord) + xform[:3, 3] s1func2struc = np.loadtxt('04_numpy/xfms/subj1/example_func2highres.mat') s1struc2std = np.loadtxt('04_numpy/xfms/subj1/highres2standard.mat') s2func2struc = np.loadtxt('04_numpy/xfms/subj2/example_func2highres.mat') s2struc2std = np.loadtxt('04_numpy/xfms/subj2/highres2standard.mat') s1func2std = concat(s1struc2std, s1func2struc) s2func2std = concat(s2struc2std, s2func2struc) s2std2func = npla.inv(s2func2std) s1func2s2func = concat(s2std2func, s1func2std) print('Subject 1 functional -> Subject 2 functional affine:') print(s1func2s2func) testcoords = np.array([[ 0, 0, 0], [-5, -20, 10], [20, 25, 60]], dtype=np.float32) def dist(p1, p2): return np.sqrt(np.sum((p1 - p2) ** 2)) for c in testcoords: xc = transform(s1func2s2func, c) d = dist(c, xc) c = '{:6.2f} {:6.2f} {:6.2f}'.format(*c) xc = '{:6.2f} {:6.2f} {:6.2f}'.format(*xc) print('Transform: [{}] -> [{}] (distance: {})'.format(c, xc, d))
 % The purpose of this comment is purely % to make life difficult for you. Sorry % about that. I'm not really sorry. 128.3 100.8 67.2 120.1 150.2 53.0 64.2 139.3 46.7 118.1 125.8 153.1 83.2 115.9 3.4 126.3 92.2 104.7 131.2 29.3 89.3 118.8 119.2 80.1 121.2 35.0 66.2 153.3 43.7 102.1 147.8 160.1 94.2 140.9 70.4 124.3 124.2 93.7 100.2 32.3 91.3 146.8 137.2 129.1 157.2 -22.0 75.2 90.3 33.7 86.1 74.8 90.1 114.2 81.9 72.4 135.3 85.2 102.7 58.2 55.3 75.3 87.8 84.2 112.1 131.2 57.0 150.2 73.3 41.7 110.1 78.8 102.1 116.2 134.9 34.4 74.3 150.2 52.7 89.2 21.3 79.3 83.8 78.2 103.1 96.2 26.0 151.2 122.3 46.7 113.1 143.8 80.1 61.2 136.9 8.4 94.3 76.2 123.7 150.2 10.3 93.3 157.8 154.2 79.1 155.2 8.0 63.2 120.3 12.7 130.1 105.8 111.1 66.2 99.9 54.4 120.3 113.2 128.7 110.2 46.3 111.3 126.8 65.2 90.1 101.2 36.0 116.2 139.3 36.7 91.1 88.8 94.1 90.2 92.9 -0.6 46.3 80.2 105.7 88.2 -11.7 149.3 119.8 134.2 124.1 89.2 21.0 133.2 113.3 28.7 139.1 136.8 82.1 141.2 90.9 11.4 97.3 109.2 137.7 120.2 32.3 141.3 149.8 115.2 115.1 105.2 51.0 77.2 130.3 -4.3 124.1 141.8 162.1 95.2 130.9 -10.6 114.3 132.2 134.7 79.2 69.3 141.3 77.8 135.2 167.1 103.2 55.0 153.2 68.3 33.7 136.1 125.8 85.1 148.2 114.9 76.4 57.3 147.2 125.7 153.2 45.3
 13,7,3,18,15,3,12,11,9,9 13,1,7,17,16,13,18,9,18,6 9,19,16,3,18,3,19,12,9,6 2,11,6,12,2,11,15,9,3,9 2,12,1,7,4,3,6,6,2,4 10,8,14,1,17,19,8,19,2,9 18,14,2,11,17,14,6,16,14,18 6,8,13,16,11,17,16,5,16,15 6,5,4,18,6,14,19,8,4,15 15,17,12,10,17,12,5,9,18,6
 1 3 14 3 4 7 12 5 15 5 14 4 15 19 7 17 7 15 16 3 15 14 17 9 7 8 4 5 15 4 11 5 17 10 3 19 14 4 18 3
 1.027343449 -0.01854307437 0.02702291658 -3.429567172 0.01572791398 0.9487250481 -0.30721057 17.65058627 -0.02892982284 0.2868726435 1.077910798 -3.247641029 0 0 0 1
 0.9998006214 -0.007506170473 -0.00206080048 -37.86830353 0.01249141095 0.863260387 0.4957794812 -33.77969415 0.03530937349 -0.4932384691 1.042606617 27.59239864 0 0 0 1
 1.0271367 -0.01315117882 -0.005127727479 -3.084298759 0.002836833979 0.9879611849 -0.002646076731 -0.4778179727 0.004268282598 -0.0002074879811 1.067805712 25.30182119 0 0 0 1
 1.077742594 -0.04288767681 -0.08886849541 -40.1774847 0.03613742149 1.017656652 0.2363464233 -27.41273922 0.07295070007 -0.3129031707 1.14704109 -0.4162223149 0 0 0 1
 1.027343449 -0.01854307437 0.02702291658 -3.429567172 0.01572791398 0.9487250481 -0.30721057 17.65058627 -0.02892982284 0.2868726435 1.077910798 -3.247641029 0 0 0 1
 0.9998006214 -0.007506170473 -0.00206080048 -37.86830353 0.01249141095 0.863260387 0.4957794812 -33.77969415 0.03530937349 -0.4932384691 1.042606617 27.59239864 0 0 0 1
 1.0271367 -0.01315117882 -0.005127727479 -3.084298759 0.002836833979 0.9879611849 -0.002646076731 -0.4778179727 0.004268282598 -0.0002074879811 1.067805712 25.30182119 0 0 0 1
 1.077742594 -0.04288767681 -0.08886849541 -40.1774847 0.03613742149 1.017656652 0.2363464233 -27.41273922 0.07295070007 -0.3129031707 1.14704109 -0.4162223149 0 0 0 1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!