Skip to main content
added 33 characters in body; added 1 character in body
Source Link
hpaulj
  • 1.5k
  • 1
  • 9
  • 16
np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

The repeat could be applied to all of y without loop with

n=y.shape[0]
X = np.repeat([x]*n, y.flat).reshape(n, -1)

But the join still has to be done iteratively.

[' '.join(I) for I in X]
np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

The repeat could be applied to all of y without loop with

n=y.shape[0]
np.repeat([x]*n, y.flat).reshape(n, -1)

But the join still has to be done iteratively.

np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

The repeat could be applied to all of y without loop with

n=y.shape[0]
X = np.repeat([x]*n, y.flat).reshape(n, -1)

But the join still has to be done iteratively.

[' '.join(I) for I in X]
added 167 characters in body; added 4 characters in body
Source Link
hpaulj
  • 1.5k
  • 1
  • 9
  • 16
np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

The repeat could be applied to all of y without loop with

n=y.shape[0]
np.repeat([x]*n, y.flat).reshape(n, -1)

But the join still has to be done iteratively.

np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.

The repeat could be applied to all of y without loop with

n=y.shape[0]
np.repeat([x]*n, y.flat).reshape(n, -1)

But the join still has to be done iteratively.

Source Link
hpaulj
  • 1.5k
  • 1
  • 9
  • 16

np.array([' '.join( np.repeat(x, z)) for z in y ])

repeat handles the repetition part for row of y nicely. The rest is just iteration on the rows. We don't need the generality of apply_along_axis here.