os.path.join()函数

os.path.join()函数:连接两个或更多的路径名组件(拼接文件路径)

import os
#数组操作,即合并数组
seq1 = ['hello','good','boy','doiido']
msg1 = ' '.join(seq1)
msg2=','.join(seq1)
print(msg1)
print(msg2)
#路径操作,即合并目录
msg6 = os.path.join('E:/hello/','good/boy/','doiido')
print(msg6)
#对字符串操作
seq2 = 'hellogoodboy doiido'
msg3 = ':'.join(seq2)
print(msg3)
#4.对字典进行操作
seq4 = {'hello':1,'good':2,'boy':3,'doiido':4}
msg5 = ':'.join(seq4)
print(msg5)

运行结果为:

hello good boy doiido
hello,good,boy,doiido
E:/hello/good/boy/doiido
h:e:l:l:o:g:o:o:d:b:o:y: :d:o:i:i:d:o
hello:good:boy:doiido

os.path.isdir()用于判断某一对象(需提供绝对路径)是否为目录
os.path.isfile()用于判断某一对象(需提供绝对路径)是否为文件

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
《python数据分析基础教程》 ⼀、导⼊常⽤numpy模块 from numpy import * //可以直接引⽤numpy中的属性XXX import numpy as np //引⽤numpy中的属性⼀定要np.XXX ⼆、常⽤函数以及转化关系 np.arange() 对应 python中的range() np.array() 对应 python中的list np.dtype() 对应 python中的type() tolist()函数可以将numpy数组转换成python列表: 列表转为数组: warning:Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample. 这个warning主要就是有些函数参数应该是输⼊数组,当输⼊列表时就会警告!! 三、numpy中数组操作函数 数组组合函数 将ndarray对象构成的元组作为参数输⼊ (1)⽔平组合:hstack((a,b)) 或者concatenate((a,b),axis=1) (2)垂直组合:vstack((a,b)) 或者concatenate((a,b),axis=0) (3)列组合:column((a,b)) (4)⾏组合:row_stack((a,b)) 数组的分割函数 (1)⽔平分割:hsplit(a,3) 或者 split(a,3,axis=1) (2)垂直分割:vsplit(a,3) 或者 split(a,3,axis=0) 四、⽂件处理——os库 1.os.system() 运⾏shell命令 2.os.listdir(path) 获得⽬录中的内容 3.os.mkdir(path) 创建⽬录 4.os.rmdir(path) 删除⽬录 5.os.isdir(path) os.isfile(path) 判断是否为⽬录或者⽂件 6.os.remove(path) 删除⽂件 7.os.rename(old, new) 重命名⽂件或者⽬录 8.os.name 输出字符串指⽰正在使⽤的平台。如果是window 则⽤'nt'表⽰,对于Linux/Unix⽤户,它是'posix' 9.os.path.join() 在⽬录后⾯接上⽂件名 10.os.path.split() 返回⼀个路径的⽬录名和⽂件名 11.os.path.splitext() 分离⽂件名与扩展名 12.os.path.getsize(name) 获得⽂件⼤⼩,如果name是⽬录返回0L 14.os.path.abspath(")获得当前路径 15.os.path.dirname()返回⼀个路径的⽬录名 五、使⽤matplotlib画图(第九章 ) 前⾯⼏个列⼦主要讲解了通过多项式函数通过plt.plot()函数构建绘图,补充⼀下在机器学习中散点绘制 import numpy as np import matplotlib.pyplot as plt fig=plt.figure() ax=fig.add_subplot(111) x1=[2, 2.6, 2.8] y1=[2, 2.4, 3] x2=[4,5 ,6] y2=[1.3, 2, 1.2] ax.scatter(x1,y1,s=20,c='red') ax.scatter(x2,y2,s=50,c='blue') plt.show() 另外:做数据分析——sklearn库 from sklearn import preprocessing 数据预处理:归⼀化、标准化、正则化处理 from sklearn import preprocessing preprocessing.normalize(features, norm='l2')//正则化
智能计算系统实验2 实验2.1:基于三层神经⽹络实现⼿写数字识别 实验⽬的 1. 实现三层神经⽹络模型进⾏⼿写数字分类,建⽴⼀个简单⽽完整的神经⽹络⼯程。通过本实验理解神经⽹络中基本模块的作⽤和模块 间的关系,为后续建⽴更复杂的神经⽹络实验(如风格迁移)奠定基础。 2. 利⽤⾼级编程语⾔Python实现神经⽹络基本单元的前向传播(正向传播)和反向传播计算,加深对神经⽹络中基本单元的理解,包括 全连接层、激活函数、损失函数等基本单元。 3. 利⽤⾼级编程语⾔Python实现神经⽹络构建,以及训练神经⽹络所使⽤的梯度下降算法,加深对神经⽹络训练过程的理解。 实验过程 数据集读取和预处理 train_labels = self.load_mnist(os.path.join(MNIST_DIR, TRAIN_LABEL), False) test_images = self.load_mnist(os.path.join(MNIST_DIR, TEST_DATA), True) test_labels = self.load_mnist(os.path.join(MNIST_DIR, TEST_LABEL), False) 全连接层 self.output = np.matmul(self.input, self.weight) + self.bias self.d_weight = np.dot(self.input.T, top_diff) self.d_bias = np.sum(top_diff, axis=0) bottom_diff = np.dot(top_diff, self.weight.T) self.weight = self.weight - lr * self.d_weight self.bias = self.bias - lr * self.d_bias relu层 output = np.maximum(0, self.input) bottom_diff = top_diff bottom_diff[self.input < 0] = 0 softmax层 self.prob = input_exp / np.sum(input_exp, axis=1, keepdims=True) bottom_diff = (self.prob - self.label_onehot) / self.batch_size 组⽹ self.fc2 = FullConnectedLayer(self.hidden1, self.hidden2) self.relu2 = ReLULayer() 前向传播和反向传播 h2 = self.fc2.forward(h1) h2 = self.relu2.forward(h2) h3 = self.fc3.forward(h2) dh3 = self.fc3.backward(dloss) dh2 = self.relu2.backward(dh3) dh2 = self.fc2.backward(dh2) 推导过程 实验打分标准 实验2.2:基于DLP平台实现⼿写数字分类 实验⽬的 熟悉深度学习处理器 DLP 平台的使⽤,能使⽤已封装好的 Python 接⼝的机器学习编程库 pycnml 将第2.1节的神经⽹络推断部分移植到 DLP 平台,实现⼿写数字分类。具体包括: 1. 利⽤提供 pycnml 库中的 Python 接⼝搭建⼿写数字分类的三层神经⽹络。 2. 熟悉在 DLP 上运⾏神经⽹络的流程,为在后续章节详细学习 DLP ⾼性能库以及智 能编程语⾔打下基础。 3. 与第2.1节的实验进⾏⽐较,了解 DLP 相对于 CPU 的优势和劣势 实验过程 基本就是第⼀个实验的简化版,将layer的创建换成了pycml的接⼝,接⼝调⽤参考实验⼿册即可,注意要加载2.1实验保存的模型参数。 实验打分标准

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值