Q:

In the third dimension of a numpy array, multiply the first three values by the fourth one

Here is a 3-dimensional numpy array:
import numpy as np
m = np.array([
  [ 
    [1,2,3,2], [4,5,6,3]
  ],
  [
    [7,8,9,4], [1,2,3,5]
  ]
])

For each tuple, I need to multiply the first three values by the last one (divided by 10 and rounded), and then to keep only the 3 results. For example in [1,2,3,2]:

The 1 becomes: round(1 * 2 / 10) = 0
The 2 becomes: round(2 * 2 / 10) = 0
The 3 becomes: round(3 * 2 / 10) = 1

So, [1,2,3,2] becomes: [0,0,1].
And the complete result will be:
[
  [ 
    [0,0,1], [1,2,2]
  ],
  [
    [3,3,4], [1,1,2]
  ]
]

I tried to separate the last value of each tuple in a alpha variable, and the 3 first values in a rgb variable.
alpha = m[:, :, 3] / 10
rgb = m[:, :, :3]

But after that I'm a beginner in Python and I really don't know how to process these arrays.
A little help from an experienced Python-guy will be most welcome.

A:

Try this
n = np.rint(m[:,:,:3] *  m[:,:,[-1]] / 10).astype(int)

Out[192]:
array([[[0, 0, 1],
        [1, 2, 2]],

       [[3, 3, 4],
        [0, 1, 2]]])

