File 00_simslope/simslope0.py changed (mode: 100644) (index 47a2474..d7ebf1d) |
13 |
13 |
#import tensorflow as tf |
#import tensorflow as tf |
14 |
14 |
#from tensorflow import keras |
#from tensorflow import keras |
15 |
15 |
import numpy as np |
import numpy as np |
16 |
|
#To allow premature exit. |
|
17 |
16 |
import sys |
import sys |
18 |
17 |
|
|
19 |
18 |
# open file |
# open file |
|
... |
... |
d=[[int(x) for x in line.split()] for line in f] |
22 |
21 |
f.close() |
f.close() |
23 |
22 |
|
|
24 |
23 |
# copy to classes and data. |
# copy to classes and data. |
|
24 |
|
#The cconvoluted statements below do pre-allocation of memory. |
25 |
25 |
#classes contains the slope data. |
#classes contains the slope data. |
26 |
26 |
#data contains the point data. |
#data contains the point data. |
27 |
27 |
classes=[None]*len(d) |
classes=[None]*len(d) |
|
... |
... |
for a in range(0,len(d)): |
33 |
33 |
for b in range(1,len(d[a])): |
for b in range(1,len(d[a])): |
34 |
34 |
data[a][b-1] = d[a][b] |
data[a][b-1] = d[a][b] |
35 |
35 |
|
|
36 |
|
print(len(classes)) |
|
37 |
|
print(len(data)) |
|
38 |
|
print(len(data[0])) |
|
|
36 |
|
print('dimension of classes =',len(classes)) |
|
37 |
|
print('dimension of data =',len(data),'x',len(data[0])) |
39 |
38 |
|
|
40 |
39 |
# normalize each row of data |
# normalize each row of data |
41 |
40 |
normdata=[[None]*len(data[0]) for i in range(len(data))] |
normdata=[[None]*len(data[0]) for i in range(len(data))] |
|
... |
... |
for a in range(0,len(data)): |
45 |
44 |
for b in range(0,len(data[a])): |
for b in range(0,len(data[a])): |
46 |
45 |
normdata[a][b] = ((float(data[a][b])-s)/(t-s)) |
normdata[a][b] = ((float(data[a][b])-s)/(t-s)) |
47 |
46 |
|
|
48 |
|
print(len(normdata)) |
|
49 |
|
print(len(normdata[0])) |
|
50 |
|
sys.exit() |
|
|
47 |
|
print('dimension of normdata = ',len(normdata),'x',len(normdata[0])) |
|
48 |
|
|
|
49 |
|
|
51 |
50 |
classes=np.array(classes) |
classes=np.array(classes) |
52 |
51 |
data=np.array(normdata) |
data=np.array(normdata) |
53 |
52 |
|
|
54 |
53 |
print("data has shape", data.shape) |
print("data has shape", data.shape) |
55 |
54 |
print("classes has shape ", classes.shape) |
print("classes has shape ", classes.shape) |
56 |
|
|
|
|
55 |
|
sys.exit() |
57 |
56 |
# convert classes to one hot vectors (each vector position is a class) |
# convert classes to one hot vectors (each vector position is a class) |
58 |
57 |
# don't need this, but left it in here in case I ever do |
# don't need this, but left it in here in case I ever do |
59 |
58 |
# i.e. convert classes like 1 2 3 4 to [1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1] |
# i.e. convert classes like 1 2 3 4 to [1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1] |