[Numpy-discussion] oblique text
Pauli Virtanen
pav at iki.fi
Tue Oct 4 16:22:48 EDT 2011
04.10.2011 21:10, Alexandre Leray kirjoitti:
[clip]
> But it is not very flexible. For instance, I'd like to control the "line
> spacing" (by adding extra spaces in between letters since it isn't real
> lines). I just found numpy and I have the intuition that it could do the
> job since it deals with matrices.
>
> Am I right? If so how would you do such a thing?
import numpy as np
def make_oblique(words):
n = max(2*len(word) for word in words) + len(words)
canvas = np.zeros((n, n), dtype='S1')
canvas[...] = ' ' # ye mighty FORTRAN, we beseech thee
for j, word in enumerate(words):
i = np.arange(len(word))
canvas[i+j, 2*i] = list(word)
canvas[:,-1] = '\n'
return canvas.tostring().rstrip()
--
Pauli Virtanen
More information about the NumPy-Discussion
mailing list