[Numpy-discussion] oblique text
Wed Oct 5 05:29:08 CDT 2011
exactly what I wanted!
On 04/10/2011 22:22, Pauli Virtanen wrote:
> 04.10.2011 21:10, Alexandre Leray kirjoitti:
>> 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()
More information about the NumPy-Discussion