Summation of massive amounts with weights

I have a two-dimensional numpy array.

Each line has three elements in length and is an integer 0-3. This is a 6-bit integer, with each cell representing two bits in order.

I am trying to convert them into a complete whole.

eg.

for i in range(len(myarray)): myarray[i] = myarray[i][0] * 16 + myarray[i][1] * 4 + myarray[i][2] 

eg. I try to summarize each line, but according to a specific weight vector [16,4,1].

What is the most elegant way to do this? I think I need to make some kind of point product, followed by the amount, but I'm not 100% sure where to make the point.

+7
source share
1 answer

The inclination of the point product is correct, and it includes the amount you need. So, to get the sum of the products of the elements of the target array and 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]) 
+12
source

All Articles