Numpy Array summing with weights

前端 未结 1 1105
孤街浪徒
孤街浪徒 2020-12-17 17:30

I have a two dimensional numpy array.

Each row is three elements long and is an integer 0-3. This represents a 6 bit integer, with each cell representing two bits, i

1条回答
  •  一个人的身影
    2020-12-17 17:53

    The dot product inclination is correct, and that includes the sum you need. So, to get the sum of the products of the elements of a target array and a set of weights:

    >>> a = np.array([[0,1,2],[2,2,3]])
    >>> a
    array([[0, 1, 2],
           [2, 2, 3]])
    >>> weights = np.array([16,4,2])
    >>> np.dot(a,weights)
    array([ 8, 46])
    

    0 讨论(0)
提交回复
热议问题