是否有一個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