[SciPy-user] once again about zeros() and ones()

Matthieu Brucher matthieu.brucher@gmail....
Sun Jul 1 10:13:17 CDT 2007


numpy.zeros((2, 3, 4), float) for instance.

Matthieu

2007/7/1, dmitrey <openopt@ukr.net>:
>
> I can't understand, which example of calling current numpy.zeros(...) is
> incompatible with mine, i.e. which one will yield other results?
> D.
>
> Matthieu Brucher wrote:
> >
> >
> > 2007/7/1, dmitrey <openopt@ukr.net <mailto:openopt@ukr.net>>:
> >
> >     Hi all,
> >     There already was some discussion about zeros() and ones() usage,
> >     but I
> >     still can't understand some things.
> >     1) currently ones(4,5, **kwargs) just yields error. Why it can't be
> >     translated to ones((4,5), **kwargs) ?
> >     See my example of Ones() below.
> >     ##############################
> >     from numpy import ones
> >     def Ones(*args, **kwargs):
> >         if type(args[0]) in (type(()), type([])):
> >             return ones(*args, **kwargs)
> >         else: return ones(tuple(args), **kwargs)
> >     #############################
> >     if __name__ == '__main__':
> >         print Ones((2,2))
> >         print 2*Ones([2,2])
> >         print 3*Ones(2,2)
> >         print 4*Ones(2,2,2, dtype=float)
> >         print 5*Ones((2,2,2), dtype='float')
> >         print 6*Ones([2,2,2], dtype='int')
> >         print 7*Ones(3,3, dtype=int, order = 'C')
> >         print 8*Ones((3,3), dtype='int')
> >         print 9*Ones(3, dtype='int')
> >         print 10*Ones((3,), dtype='int')
> >     #############################
> >
> >
> > The first argument is a shape, the second is the type of the data.
> > Python has no way of knowing that the second argument is part of the
> > shape and not the type. This way, the arguments are defined correctly,
> > although you could make a wrapper *args, **kwargs and forcing people
> > to use explicitely dtype=float, which they won't do, thus leading to a
> > lot of trouble and errors.
> >
> > Matthieu
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user@scipy.org
> > http://projects.scipy.org/mailman/listinfo/scipy-user
> >
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070701/5cc6168c/attachment-0001.html 


More information about the SciPy-user mailing list