0

Now in numpy version 1.20.0 there is np.broadcast_shapes that will broadcast multiple shapes together, is there something similar but for broadcasting the strides - something like np.broadcast_strides?

Say I have two arrays A and B with the respective shapes (1,) and (10,). I want to get the resulting strides from out = np.broadcast_to(A, B.shape) (which will be out.strides = (0,) in this case), but I don't care about doing the actual broadcast.

Kevin
  • 3,096
  • 2
  • 8
  • 37
  • Hmm, realized that you can create a numpy array without allocating memory by doing ```np.empty(shape, dtype=[])``` – Kevin Apr 25 '21 at 15:52
  • That `dtype=[]` puzzled me until I saw your comment, and then realized it's a 0 field compound dtype. But does that help? Even if the shape is right, the strides will be (0,). – hpaulj Apr 25 '21 at 16:16
  • No, you're right. Even though broadcasting is basically just setting the stride to 0 for the broadcasted dimensions - it will not take into account which dimensions should *not* be broadcasted. – Kevin Apr 25 '21 at 16:42

0 Answers0