python的numpy.prod函数运行实例详解

官网

numpy.prod 数据乘法

当使用整数类型时,算术是模块化的,溢出时不会出错。这意味着,在32位平台上:

(C:\ProgramData\Anaconda3) C:\Users\Administrator>python
Python 3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.
1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> x = np.array([536870910, 536870910, 536870910, 536870910])
>>> np.prod(x)
16
>>> np.prod([])
1.0
>>>  np.prod([1.,2.])
  File "<stdin>", line 1
    np.prod([1.,2.])
    ^
IndentationError: unexpected indent
>>> np.prod([1.,2.])
2.0
>>> np.prod([[1.,2.],[3.,4.]])
24.0
>>> np.prod([[1.,2.],[3.,4.]], axis=1)
array([ 2., 12.])
>>> np.prod([[1.,2.],[3.,4.]], axis=0)
array([3., 8.])
>>>  x = np.array([1, 2, 3], dtype=np.uint8)
  File "<stdin>", line 1
    x = np.array([1, 2, 3], dtype=np.uint8)
    ^
IndentationError: unexpected indent
>>> x = np.array([1, 2, 3], dtype=np.uint8)
>>> x
array([1, 2, 3], dtype=uint8)
>>> x = np.array([1, 2, 3], dtype=np.uint8)
>>> x
array([1, 2, 3], dtype=uint8)
>>> np.prod(x).dtype == np.uint
True
>>> x = np.array([1, 2, 3], dtype=np.int8)
>>> x
array([1, 2, 3], dtype=int8)
>>> np.prod(x).dtype == int
True
>>> x
array([1, 2, 3], dtype=int8)
>>> x = np.array([1, 2, 3])
>>> x
array([1, 2, 3])
>>> np.prod(x)
6
>>>

    原文作者:wyx100
    原文地址: https://blog.csdn.net/wyx100/article/details/80998864
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞