Not really more "Sage" way but

sage: from PIL import Image
sage: nmax = 256
sage: I = Image.new('1', (nmax,nmax))
sage: I.putdata([int(binomial(n,k)%2 == 1) for n in range(nmax) for k
in range(nmax)])
sage: I.save('/tmp/tmp.png')

Anyway, any Python is good to be used in Sage. You should be more
precise with what you want...

Vincent
PS: Note that the GUI support for matplotlib is somehow broken in
Sage... and this is a very sad.

2014-11-27 15:08 UTC−06:00, Christophe Bal <[email protected]>:
> Hello.
>
> Is it possible to do the same thing as the following code in "pure" Sage
> coding ?
>
> *Christophe BAL*
> *Enseignant de mathématiques en Lycée*
> *et développeur Python amateur*
>
> *--**------**------**--- **CODE **---**------**------**--*
> *import matplotlib.pyplot as plt*
> *import numpy as np*
> *from sympy import binomial*
>
> *nmax = 200*
>
> *im = np.zeros((nmax+1, nmax+1, 3))*
>
> *for n in range(nmax):*
> *    for k in range(n+1):*
> *        if binomial(n, k) % 2 == 1:*
> *            im[k, n] = (255, 255, 255)*
>
> *im = im.astype(np.uint8)*
>
> *plt.imshow(im)*
> *plt.axis('off')*
> *plt.show()*
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to