2 added 138 characters in body edited May 27 '14 at 19:08 k20 76233 silver badges33 bronze badges Edit: removed confusing code Yes there is a shortcut, here's some Python code:  import numpy as np d = 3 D = np.repeat(np.identity(d), d, axis=1) print('D:') print D print print('x:') x = np.arange(d*d, dtype=float) print x print print('D * x:') print D.dot(x) print print('shortcut:') print x.reshape((d, d)).sum(axis=1) print  import numpy as np d = 3 D = np.repeat(np.identity(d), d, axis=1) print('D:') print D print print('x:') x = np.arange(d*d, dtype=float) print x print print('D * x:') print D.dot(x) print print('shortcut:') print x.reshape((d, d)).sum(axis=1) print  output:  D: [[ 1. 1. 1. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 1. 1. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 1. 1. 1.]] D: [[ 1. 1. 1. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 1. 1. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 1. 1. 1.]] x: [ 0. 1. 2. 3. 4. 5. 6. 7. 8.]   D * x: [ 3. 12. 21.] D * x: [ 3. 12. 21.] shortcut: [ 3. 12. 21.]  Yes there is a shortcut, here's some Python code:  import numpy as np d = 3 D = np.repeat(np.identity(d), d, axis=1) print('D:') print D print print('x:') x = np.arange(d*d, dtype=float) print x print print('D * x:') print D.dot(x) print print('shortcut:') print x.reshape((d, d)).sum(axis=1) print  output:  D: [[ 1. 1. 1. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 1. 1. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 1. 1. 1.]] x: [ 0. 1. 2. 3. 4. 5. 6. 7. 8.]   D * x: [ 3. 12. 21.] shortcut: [ 3. 12. 21.]  Edit: removed confusing code Yes there is a shortcut, here's some Python code:  import numpy as np d = 3 D = np.repeat(np.identity(d), d, axis=1) print('D:') print D print print('x:') x = np.arange(d*d, dtype=float) print x print print('D * x:') print D.dot(x) print print('shortcut:') print x.reshape((d, d)).sum(axis=1) print  output:  D: [[ 1. 1. 1. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 1. 1. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 1. 1. 1.]] x: [ 0. 1. 2. 3. 4. 5. 6. 7. 8.] D * x: [ 3. 12. 21.] shortcut: [ 3. 12. 21.]  1 answered May 27 '14 at 18:17 k20 76233 silver badges33 bronze badges Yes there is a shortcut, here's some Python code:  import numpy as np d = 3 D = np.repeat(np.identity(d), d, axis=1) print('D:') print D print print('x:') x = np.arange(d*d, dtype=float) print x print print('D * x:') print D.dot(x) print print('shortcut:') print x.reshape((d, d)).sum(axis=1) print  output: D: [[ 1. 1. 1. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 1. 1. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 1. 1. 1.]] x: [ 0. 1. 2. 3. 4. 5. 6. 7. 8.] D * x: [ 3. 12. 21.] shortcut: [ 3. 12. 21.]