You're reinventing Numeric Python. On Tue, Dec 20, 2011 at 11:45 AM, Nathan Rice < nathan.alexander.r...@gmail.com> wrote:
> Elementwise provides a proxy object for iterables which supports > chained method calls, as well as elementwise expressions and some > built-in functions. > > Example: > > class ExampleList(ElementwiseProxyMixin, list): > def __new__(cls, iterable): > return list.__new__(cls, iterable) > foo = ExampleList([1, 2, 3, 4]) > > # You could also do: efoo = ElementwiseProxy(foo) > efoo = foo.each > > assert list(efoo.bit_length()) == [1, 2, 2, 3] > print "bit length: ", list(efoo.bit_length()) > assert list(efoo + 1) == [2, 3, 4, 5] > print "with addition of 1: ", list(efoo + 1) > assert list(efoo * 2) == [2, 4, 6, 8] > print "with multiplication by 2: ", list(efoo * 2) > assert list(efoo == 2) == [False, True, False, False] > print "testing equality: ", efoo == 2 > assert list((efoo + 1) * 2 + 3) == [7, 9, 11, 13] > print "chaining addition and multiplication: ", (efoo + 1) * 2 + 3 > > Each ElementwiseProxy also has a "parent" attribute so you can > backtrack in the chain as needed rather than store each intermediate > value, if you think you might need them. > > There are still some issues with proper support of things like bool() > and int(), which refuse to return things that are not of the correct > type. > > Get it: > > PyPi: http://pypi.python.org/pypi/elementwise/0.111220 > GitHub: https://github.com/nathan-rice/Elementwise > > This was developed as a proof of concept for expanding the role of > element-wise syntax in python, and to that end I welcome comments. > > Nathan Rice > -- > http://mail.python.org/mailman/listinfo/python-announce-list > > Support the Python Software Foundation: > http://www.python.org/psf/donations/ >
-- http://mail.python.org/mailman/listinfo/python-list