科学网

 找回密码
  注册
Python小code对原文件进行替换
赵志强 2019-6-17 19:04
import os import fileinput with fileinput.input('tip.data',backup='.bak',inplace=True) as f: for line in f: line = line.rstrip().replace('0.417000','0.5564') &nb ...
个人分类: Python|1595 次阅读|没有评论
水分子模拟之TIP4P/2005
热度 1 赵志强 2019-6-17 17:13
参考资料: http://www.orsi.sems.qmul.ac.uk/downloads.html Tip4p2005 data文件格式: LAMMPS'data.'description 3atoms 2bonds 1&n ...
个人分类: MD|6454 次阅读|2 个评论 热度 1
Python Numpy 创建数组
赵志强 2019-6-12 23:17
参考: https://www.runoob.com/numpy/numpy-array-from-existing-data.html numpy.empty numpy.empty 方法用来创建一个指定形状(shape)、数据类型(dtype)且未初始化的数组: numpy.empty(shape,dtype=float,order='C') shape 数组形状 dtype 数据类型, ...
个人分类: Python|2437 次阅读|没有评论
Python NumPy 数组属性
赵志强 2019-6-12 22:30
ndarray.ndim 秩,用于返回数组的维数 ndarray.shape 数组的维度,对于矩阵,n 行 m 列 ndarray.size 数组元素的总个数,相当于 .shape 中 n*m 的值 ndarray.dtype ndarray 对象的元素类型 ndarray.itemsize ndarray 对象中每个元素的大小,以字节为单位 ndarray.flags ndarray 对象的内存 ...
个人分类: Python|1831 次阅读|没有评论
NumPy 数据类型 dtype
赵志强 2019-6-12 22:03
本文参考自: https://www.runoob.com/numpy/numpy-dtype.html Numpy支持多种数据类型: bool_ 布尔型数据类型(True 或者 False) int_ 默认的整数类型(类似于 C 语言中的 long,int32 或 int64) intc 与 C 的 int 类型一样,一般是 int32 或 int 64 intp 用于索引的整数类型(类似于 C 的 ssize_t ...
个人分类: Python|7182 次阅读|没有评论
Python Numpy库之Ndarray 对象
赵志强 2019-6-12 20:43
本文参考自: https://www.runoob.com/numpy/numpy-ndarray-object.html NumPy 最重要的一个特点是其 N 维数组对象 ndarray,它是一系列同类型数据的集合,以 0 下标为开始进行 集合中元素的索引。 ndarray 对象是用于存放同类型元素的多维数组。 ndarray 中的每个元素在内存中都有相同存储大小的区域。 创建一个 n ...
个人分类: Python|1657 次阅读|没有评论
Python linecache用法:随机读取文件指定行
赵志强 2019-6-12 11:49
本文参考自:http://c.biancheng.net/view/2556.html linecache 模块允许从 Python 源文件中随机读取指定行,并在内部使用缓存优化存储。由于该模块主要被设计成读取 Python 源文件,因此它会用 UTF-8 字符集来读取文本文件。 实际上,使用 linecache 模块也可以读取其他文件,只要该文件使用了 UTF-8 字符 ...
个人分类: Python|2513 次阅读|没有评论
Python with用法:自动关闭文件
赵志强 2019-6-12 11:30
在前面的程序中,我们都采用了程序主动关闭文件的方式。实际上, Python 提供了 with 语句来管理资源关闭。比如可以把打开的文件放在 with 语句中,这样 with 语句就会帮我们自动关闭文件。 with 语句的语法格式如下: with context expression : with 代码块 在上面的语法格式中,conte ...
个人分类: Python|2497 次阅读|没有评论
Python中fileinput模块使用范例
赵志强 2019-6-12 10:51
本文参考自: https://blog.csdn.net/Jerry_1126/article/details/41926407 https://www.runoob.com/python/att-string-rstrip.html 1. 利用fileinput循环读取一个文件所有行 ...
个人分类: Python|2442 次阅读|没有评论

本页有 1 篇博文因作者的隐私设置或未通过审核而隐藏

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 19:02

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部