目录
1.超过二维的张量写进csv
2.翻转矩阵与绘制热力图
3.切片
4.np按块复制
1.超过二维的张量写进csv
#(20,204,273) -> (4080,273)
ycsv = []
for i in range(20):
ycsv.append(y[i, 8, :, :].reshape(204,273))
with open('y.csv','w',encoding='utf-8') as y_obj:
writer = csv.writer(y_obj)
for j in range(20):
writer.writerows(ycsv[j])
data = pd.read_csv('y.csv',encoding='utf-8')
print(data.shape)
2.翻转矩阵与绘制热力图
#上下翻转矩阵
y = y[::-1,:]
#度数符号
du = chr(176)
#vmax设置颜色条上界,vmin设置下界,cmap设置颜色条样例
ax1 = sns.heatmap(predy,cmap = 'hot_r',vmax = 160,vmin = 0)
#xticks中可以用ticks来设置labels打点位置,fontsize设置字体大小,rotation设置旋转角度
plt.xticks(ticks=[0,34,68,102,136,170,204,238,272],labels=[str(x)+du+'E' for x in range(109,118,1)],fontsize=10,rotation=360)
plt.yticks(ticks=[29,64,99,134,169,204], labels=[str(x)+du+'N' for x in [25,24,23,22,21,20]],fontsize=10)
#设置labels与图片的距离
plt.tick_params(axis='x',pad=5)
plt.tick_params(axis='y',pad=5)
figure1 = ax1.get_figure()
figure1.savefig('predy.jpg')
3.切片
import numpy as np
a = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
b = a[:5]
c = a[6:9] #前面六个省略,从第七个开始取三个,左开右闭
d = a[9:15] #连续读取就顶着前面的继续切
b, c, d
4.np按块复制
import numpy as np
a = np.zeros((24,40,40,70))
b = np.tile(a,(30,1,1,1))
c = np.tile(a,(1,30,1,1))