为多维数组添加一列以及reshape用法注意

时间:2023-01-14 17:50:54

https://blog.csdn.net/orangefly0214/article/details/80934008参考这个了链接

下面是我自己用到的代码,亲测可用

# data = pd.read_csv("E:/backup_zhihu_spider/Malicious-URL-Detection-using-Machine-Learning-master/data/dataNN.csv",',',error_bad_lines=False)  #reading file
# data = np.array(data)
# allurl_fea=[d[0] for d in data]
# x_train, y_train = get_wordvec_word(1,url_all,y_train)#我的x_train是一个三维矩阵
# # feature=np.c_[np.ones((x_train.shape[0],x_train.shape[1],1)),x_train]#为了与x_train拼接,先构建一个全1矩阵,前面两维与x_train一样,最后一维是最内层的维度,是1维
# print(feature.shape)
# print(feature)
# data1=preprocess()[:int(0.3*len(allurl_fea))]
# data2=data1.reshape((data1.shape[0],1))#注意reshape要对转换的维度加括号!!!!!!!!!!!!!!
# print(data2.shape)