
python
伍肆柒547
知乎:伍肆柒
展开
-
在python如何实现取整
import matha = 1.57print(math.ceil(a)) # 向上取整,结果为 2print(math.floor(a)) # 向下取整,结果为 1原创 2021-08-10 14:35:14 · 185 阅读 · 0 评论 -
np.tile的用法
横向和纵向重复import numpy as npa = np.array([0, 1, 2])np.tile(a, (1, 2))Out[1]:array([[0, 1, 2, 0, 1, 2]])In [2]:np.tile(a, (2, 1))Out[2]:array([[0, 1, 2], [0, 1, 2]])原创 2021-08-07 00:16:35 · 218 阅读 · 0 评论 -
python zip的用法
简单地说,zip相当于压缩,zip(*)相当于解压例子:使用过程中的注意事项:1. 当x和y的长度不匹配时,压缩的结果如下x=[1,2]y=[1,2,3]a=zip(x,y)list(a)------------[(1, 1), (2, 2)] 当压缩的两个对象长度不等时,取小的长度2. 当x和y的长度不匹配时,解压的结果如下for zip : 当两个迭代a和b中较短的一个用完时,这将停止。for x, y in zip(a, b):# ...原创 2021-08-06 17:30:48 · 572 阅读 · 0 评论 -
pandas的使用
和numpy的区别pandas数据导入导入全部数据读取前5行和numpy的区别NumPy arrays have one dtype for the entire array, while pandas DataFrames have one dtype per column.Pandas是基于Numpy构建的,让Numpy为中心的应用变得更加简单。pandas数据导入导入全部数据pd.read_csv(filename):从CSV文件导入数据pd...原创 2021-08-06 14:16:55 · 194 阅读 · 0 评论 -
Python 安装指定的版本(特定版本)的包
pip install 包名==版本号例如:pip install numpy==1.8原创 2021-08-06 10:29:52 · 621 阅读 · 0 评论 -
指定GPU训练
需要将指定GPU代码放在程序段最开始的部位。os.environ["CUDA_VISIBLE_DEVICES"] = '1'# (如果你想同时调用两块GPU的话)os.environ["CUDA_VISIBLE_DEVICES"] = '1,2'原创 2021-08-05 08:42:03 · 259 阅读 · 0 评论 -
python 检查是否安装某个库
try: import sympy # XXX 要验证是否安装的库名except ImportError: print('模块不存在')原创 2021-08-02 21:22:49 · 2464 阅读 · 0 评论 -
python 根据不同的文件类型读取数据
if data_file.endswith('npy'): self.data = np.load(data_file)elif data_file.endswith('mat'): self.data = scipy.io.loadmat(data_file) self.data = self.data['feat']elif data_file.endswith('npz'): self.data = np.load(data_file) self.data.原创 2021-08-02 21:14:37 · 318 阅读 · 0 评论