我尝试将 2 个矩阵 x,y 与形状 (41) 和 (41,6) 相乘,因为它应该将单个矩阵广播到多维度中的每个箭头
我想这样做:
x*y
Run Code Online (Sandbox Code Playgroud)
但我收到这个错误
ValueError: operands could not be broadcast together with shapes (41,6) (41,)
Run Code Online (Sandbox Code Playgroud)
我有什么想念的东西可以让这一切成为可能吗?
我需要计算 python 脚本中 shell 命令输出的行数。
这个函数在有输出的情况下工作正常,但如果输出为空,它会给出错误输出中解释的错误。
我试图避免if在命令的输出为 的情况下使用语句None,但这没有帮助。
#!/usr/bin/python
import subprocess
lines_counter=0
func="nova list | grep Shutdown "
data=subprocess.check_output(func, shell=True)
if data is True:
for line in data.splitlines():
lines_counter +=1
print lines_counter
Run Code Online (Sandbox Code Playgroud)
错误输出:
data=subprocess.check_output(func, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command 'nova list | grep Shutdown ' returned non-zero exit status 1
Run Code Online (Sandbox Code Playgroud)