计算化学公社

 找回密码 Forget password
 注册 Register
Views: 6970|回复 Reply: 6
打印 Print 上一主题 Last thread 下一主题 Next thread

[算法与编程] 请教大家两个python的小问题

[复制链接 Copy URL]

239

帖子

0

威望

2333

eV
积分
2572

Level 5 (御坂)

跳转到指定楼层 Go to specific reply
楼主
1.dd = re.compile(r'Initial\scommand:[\s\S]+Title\sCard\sRequired?')请教一下各位,这个Title\sCard\sRequired我只想匹配第一个,但是由于前面开启了贪婪模式,Title\sCard\sRequired一直匹配到了最后面的第二个
有什么办法可以解决么
2.我想求两个相同大小的矩阵的对应行之间的角度,
目前我是A×B.T=C,C的第一列即是点乘;再计算每一行的模长,这样计算的。
有什么简便的方法的,比如直接np.dot(vector1,vector2)/(np.linalg.norm(vector1)
先谢谢各位了

3097

帖子

29

威望

1万

eV
积分
17221

Level 6 (一方通行)

2#
发表于 Post on 2020-3-29 06:55:59 | 只看该作者 Only view this author
本帖最后由 liyuanhe211 于 2020-3-29 07:10 编辑

1. r'Initial\scommand:[\s\S]+?Title\sCard\sRequired?'(不确定我明白你的意思了)
2. 没懂,是求两个矩阵中行向量之间的角度?能否给出一个样例出入输出?可以看看numpy.einsum(),听起来多半能用它实现

评分 Rate

参与人数
Participants 1
eV +3 收起 理由
Reason
我本是个娃娃 + 3 可爱的李大博士

查看全部评分 View all ratings

239

帖子

0

威望

2333

eV
积分
2572

Level 5 (御坂)

3#
 楼主 Author| 发表于 Post on 2020-3-29 11:03:45 | 只看该作者 Only view this author
liyuanhe211 发表于 2020-3-29 06:55
1. r'Initial\scommand:[\s\S]+?Title\sCard\sRequired?'(不确定我明白你的意思了)
2. 没懂,是求两个矩 ...

谢谢回复
1.Initial command:
/home/test/g16/l1.exe "/home/test/tmp/Gau-45062.inp" -scrdir="/home/test/tmp/"
Entering Link 1 = /home/test/g16/l1.exe PID=     45063.
  
Copyright (c) 1988,1990,1992,1993,1995,1998,2003,2009,2016,
            Gaussian, Inc.  All Rights Reserved.
  
This is part of the Gaussian(R) 16 program.  It is based on
the Gaussian(R) 09 system (copyright 2009, Gaussian, Inc.),
the Gaussian(R) 03 system (copyright 2003, Gaussian, Inc.),
the Gaussian(R) 98 system (copyright 1998, Gaussian, Inc.),
the Gaussian(R) 94 system (copyright 1995, Gaussian, Inc.),
the Gaussian 92(TM) system (copyright 1992, Gaussian, Inc.),
the Gaussian 90(TM) system (copyright 1990, Gaussian, Inc.),
the Gaussian 88(TM) system (copyright 1988, Gaussian, Inc.),
the Gaussian 86(TM) system (copyright 1986, Carnegie Mellon
University), and the Gaussian 82(TM) system (copyright 1983,
Carnegie Mellon University). Gaussian is a federally registered
trademark of Gaussian, Inc.
Initial command:
/home/test/g16/l1.exe "/home/test/tmp/Gau-45062.inp" -scrdir="/home/test/tmp/"
Entering Link 1 = /home/test/g16/l1.exe PID=     45063.
  
Copyright (c) 1988,1990,1992,1993,1995,1998,2003,2009,2016,
            Gaussian, Inc.  All Rights Reserved.
  
This is part of the Gaussian(R) 16 program.  It is based on
the Gaussian(R) 09 system (copyright 2009, Gaussian, Inc.),
the Gaussian(R) 03 system (copyright 2003, Gaussian, Inc.),
the Gaussian(R) 98 system (copyright 1998, Gaussian, Inc.),
the Gaussian(R) 94 system (copyright 1995, Gaussian, Inc.),
the Gaussian 92(TM) system (copyright 1992, Gaussian, Inc.),
the Gaussian 90(TM) system (copyright 1990, Gaussian, Inc.),
the Gaussian 88(TM) system (copyright 1988, Gaussian, Inc.),
the Gaussian 86(TM) system (copyright 1986, Carnegie Mellon
University), and the Gaussian 82(TM) system (copyright 1983,
Carnegie Mellon University). Gaussian is a federally registered
trademark of Gaussian, Inc.
比如我想截取第一个Initial command:到第一个trademark of Gaussian, Inc之间的内容,
dd = re.compile(r'Initial\scommand:([\s\S]+)trademark\sof\sGaussian,\sInc')
for one in dd.findall(text):
    print(one)
但是这样截取的是整个段落,我可以怎么做呢
2.谢谢提供的函数,
A = np.array([[1, 2], [3, 4],[1,4]])
B = np.array([[5, 6], [7, 8],[5,8]])
计算对应行的cosα,我自己这么计算也算蛮快了

1102

帖子

18

威望

6703

eV
积分
8165

Level 6 (一方通行)

計算化学の社畜

4#
发表于 Post on 2020-3-29 11:22:16 | 只看该作者 Only view this author
柒月小鱼 发表于 2020-3-29 11:03
谢谢回复
1.Initial command:
/home/test/g16/l1.exe "/home/test/tmp/Gau-45062.inp" -scrd ...

在+后面加上?切换成非贪婪模式看看

评分 Rate

参与人数
Participants 1
eV +5 收起 理由
Reason
柒月小鱼 + 5 谢谢

查看全部评分 View all ratings

Stand on the shoulders of giants

239

帖子

0

威望

2333

eV
积分
2572

Level 5 (御坂)

5#
 楼主 Author| 发表于 Post on 2020-3-29 11:35:03 | 只看该作者 Only view this author
冰释之川 发表于 2020-3-29 11:22
在+后面加上?切换成非贪婪模式看看

谢谢
我咋就没这么试一下呢,搞了我好久的说
非常谢谢

3097

帖子

29

威望

1万

eV
积分
17221

Level 6 (一方通行)

6#
发表于 Post on 2020-3-29 12:24:06 | 只看该作者 Only view this author
柒月小鱼 发表于 2020-3-29 11:03
谢谢回复
1.Initial command:
/home/test/g16/l1.exe "/home/test/tmp/Gau-45062.inp" -scrd ...

第一个问题在2L已回复
第二个问题定义一个row-wise点乘的操作就行了
  1. f = lambda x,y:np.einsum('ij,ij->i',x,y)
  2. dot_pds = f(A,B)/np.sqrt(f(A,A)*f(B,B)))
复制代码

f(A,A)等价于np.linalg.norm(A,axis=1)

239

帖子

0

威望

2333

eV
积分
2572

Level 5 (御坂)

7#
 楼主 Author| 发表于 Post on 2020-3-29 13:08:30 | 只看该作者 Only view this author
liyuanhe211 发表于 2020-3-29 12:24
第一个问题在2L已回复
第二个问题定义一个row-wise点乘的操作就行了

非常谢谢
这个比我的简单多了
学习

本版积分规则 Credits rule

手机版 Mobile version|北京科音自然科学研究中心 Beijing Kein Research Center for Natural Sciences|京公网安备 11010502035419号|计算化学公社 — 北京科音旗下高水平计算化学交流论坛 ( 京ICP备14038949号-1 )|网站地图

GMT+8, 2026-2-26 00:10 , Processed in 0.306818 second(s), 21 queries , Gzip On.

快速回复 返回顶部 返回列表 Return to list