是否有一个python等价的MATLAB命令“prod”(描述here)?python等价的MATLAB命令prod
2
A
回答
7
您可以在Python中使用reduce
:
>>> from operator import mul
>>> reduce(mul, range(1, 5))
24
或者,如果你有numpy,那么最好使用numpy.prod:
>>> import numpy as np
>>> a = np.arange(1, 10)
>>> a.prod()
362880
#Product along a axis
>>> a = np.arange(1, 10).reshape(3,3)
>>> a.prod(axis=1)
array([ 6, 120, 504])
+0
谢谢!这个不起眼的建议对我很好。 – Sophie
1
在Python中没有这样的功能,但你可以得到列表中的所有元素的产品,采用reduce
这样
myList = [1, 2, 3]
print reduce(lambda x, y: x * y, myList, 1)
相关问题
- 1. Python中的等价命令
- 2. 等价命令matlab <> opencv
- 3. python等价的Matlab的resample()
- 4. python等价于MATLAB的mxCreateDoubleMatrix
- 5. Python等价物的matlab corr2
- 6. Python等价于shell查找命令
- 7. Intellij的Eclipse等价命令
- 8. 等价命令$ USER IN windows命令行
- 9. Lua解释器的Matlab“whos”命令的等价物?
- 10. Mac等价于arecord命令?
- 11. bluetoothctl to hcitool等价命令
- 12. `tee`命令等价于* input *?
- 13. Python的等价物的MATLAB psf2otf函数
- 14. Python的等价物Matlab的持续
- 15. Matlab imfilter在Python中的等价函数
- 16. is enableProdMode();和build -prod是否等价?
- 17. Python popen命令。等待命令完成
- 18. python numpy等价于bandpower()from MATLAB
- 19. curl命令的等价http请求
- 20. CMD命令的MS-DOS等价物?
- 21. 等价的bash命令**时间**
- 22. ruby中的openssl等价命令
- 23. curl命令的宁静等价物
- 24. AIX中的jps等价命令
- 25. OS X中的GNU Linker等价命令
- 26. awk命令到PowerShell的等价
- 27. bash中的等价命令失败?
- 28. Julia等价于MATLAB的inpolygon()
- 29. Julia等价于MATLAB的`sym`?
- 30. Visual Studio等价于Unix'文件'命令
答案t他比建议的副本更好,因为它引用了来自MATLAB几乎肯定使用的用户'numpy'。 – tacaswell