import random
import numpy as np
a = []
c = 5
d = 0
while d<5:
b = []
for i in range(7):
b.append(random.random())
a.append(b)
d +=1
a = np.array(a)
a = a.reshape((5,7))
print(list(a))
print('.................................................')
f = open('gyy.csv','w')
for i in str(a): #将数据写进文件中
f.write(str(i)) #write只能将字符串形式写进文件中
f.close()
import csv
csv_reader = csv.reader(open('gyy.csv')) #将文件中数据读取出来
for row in csv_reader:
print(len(row))
open('gyy.csv').close()
import numpy as np
x = []
x = np.array(a).sum(axis = 1) #求得行和的矩阵5*1
print(len(x))
a = np.array(a) #将list形式转化一下
x = x.reshape((5,1))
ax = np.append(a,x,axis=1) #将列表 x 中数据写进列表 a 中
print(ax)
l=[]
c = x.sum()
c = c/5.0
for i in range(5):
if ax[i][7]>= c:
l.append(1)
else:
l.append(0)
l = np.array(l)
l = l.reshape((5,1))
axl = np.append(ax,l,axis=1) #将列表 l 中数据写进列表 axl 中
print(axl)
f = open('gyyy.csv','w')
for i in str(axl):
f.write(str(i))
f.close()
import numpy as np
a = []
c = 5
d = 0
while d<5:
b = []
for i in range(7):
b.append(random.random())
a.append(b)
d +=1
a = np.array(a)
a = a.reshape((5,7))
print(list(a))
print('.................................................')
f = open('gyy.csv','w')
for i in str(a): #将数据写进文件中
f.write(str(i)) #write只能将字符串形式写进文件中
f.close()
import csv
csv_reader = csv.reader(open('gyy.csv')) #将文件中数据读取出来
for row in csv_reader:
print(len(row))
open('gyy.csv').close()
import numpy as np
x = []
x = np.array(a).sum(axis = 1) #求得行和的矩阵5*1
print(len(x))
a = np.array(a) #将list形式转化一下
x = x.reshape((5,1))
ax = np.append(a,x,axis=1) #将列表 x 中数据写进列表 a 中
print(ax)
l=[]
c = x.sum()
c = c/5.0
for i in range(5):
if ax[i][7]>= c:
l.append(1)
else:
l.append(0)
l = np.array(l)
l = l.reshape((5,1))
axl = np.append(ax,l,axis=1) #将列表 l 中数据写进列表 axl 中
print(axl)
f = open('gyyy.csv','w')
for i in str(axl):
f.write(str(i))
f.close()