散点图的绘制
y_pred=[]
k = 0
x = []
for i in X_train:
y_pred.append(network.predict(i))
k += 1
x.append(k)#生成1-400的list,这样写好蠢,应该有更漂亮的写法
# x = [a for a in range(1,len(X_train)+1)]
feature = np.array([list(t) for t in zip(x,y_pred)])#合并两个list再转换成array
# print(feature)
fig, ax = plt.subplots()
# feature表示特征向量(数组),shape为m*2,label为list[]值包含0,1,2【数组更不嫌弃】
ax0 = ax.scatter(feature[:, 0], feature[:, 1], 10*(np.array(y_train)+1), np.array(y_train), marker='o', cmap='viridis')#cmap是colormap的简称,用于指定渐变色,与label关联;第三个参数10*(np.array(y_train)+1)是点的大小
fig.colorbar(ax0)
plt.show()
numpy中数值的合并(水平合并,垂直合并)
x = np.array([1,1,1]).reshape(-1,1)
y = np.array([2,2,2]).reshape(-1,1)
#水平合并
z = np.concatenate((x,y),axis=1)
z = np.hstack((x,y))
##
[[1 2]
[1 2]
[1 2]]
x = np.array([1,1,1]).reshape(1,-1)
y = np.array([2,2,2]).reshape(1,-1)
#垂直合并
z = np.concatenate((x,y),axis=0)
z = np.vstack((x,y))
##
[[1 1 1]
[2 2 2]]
numpy中数组和list的转换
list转array =》array = np.array(list)
array 转list =》list = array.tolist()
Python将list元素转存为CSV文件
import pandas as pd
list=[[1,2,3],[4,5,6],[7,8,9]]
name1=['one','two','three']#列名(default从0开始递增)
name2=['a','b','c']#行名(default从0开始递增)
test=pd.DataFrame(columns=name1,index=name2,data=list)#参数columns和index都是可选参数
print(test)
test.to_csv('./test.csv',index=False,header=0,encoding='gbk')#index=False表示不显示行名,header=0表示不显示列名,当然0和False是一样的