Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Elementwise 0.120116 -//- beta release -//- Lazily compute functions,method calls and operations on all elements of an iterable (or graph).

Reply
Thread Tools

Elementwise 0.120116 -//- beta release -//- Lazily compute functions,method calls and operations on all elements of an iterable (or graph).

 
 
Nathan Rice
Guest
Posts: n/a
 
      01-16-2012
Elementwise provides helpful proxy objects which let you perform a
series of computations on every element of an iterable or graph, in a
lazy manner.

Docs: http://packages.python.org/elementwise/
GitHub: https://github.com/nathan-rice/Elementwise
Examples:

The standard ElementwiseProxy:

>>> nums = ElementwiseProxy([1, 2, 3, 4)
>>> print nums.bit_length()

1, 2, 2, 3
>>> nums + 1

2, 3, 4, 5
>>> print nums * 2

2, 4, 6, 8
>>> print nums == 2

False, True, False, False
>>> print ((nums + 1) * 2 + 3).apply(float)

7.0, 9.0, 11.0, 13.0
>>> print (nums.apply(float) + 0.0001).apply(round, 2)

1.0, 2.0, 3.0, 4.0
>>> print abs(nums - 3)

2, 1, 0, 1
>>> print (nums * 2 + 3) / 4
>>> print efoo2.undo(3)

1, 2, 3, 4
>>> print ((nums * 2 + 3) / 4).replicate([2, 2, 3, 3])

1, 1, 2, 2
>>> words = ElementwiseProxy(["one", "two", "three", "four"])
>>> print (words + " little indians").upper().split("

").apply(reversed).apply("_".join) * 2
'INDIANS_LITTLE_ONEINDIANS_LITTLE_ONE',
'INDIANS_LITTLE_TWOINDIANS_LITTLE_TWO',
'INDIANS_LITTLE_THREEINDIANS_LITTLE_THREE',
'INDIANS_LITTLE_FOURINDIANS_LITTLE_FOUR'

The PairwiseProxy:

>>> nums = PairwiseProxy([1, 2, 3, 4])
>>> nums + [1, 2, 3, 4]

2, 4, 6, 8
>>> nums * [2, 2, 3, 3]

2, 4, 9, 12
>>> nums == [2, 2, 3, 5]

False, True, True, False
>>> (nums.apply(float) / itertools.count(2) +

itertools.count(1)).apply(round, args=itertools.repeat([2]))
1.5, 2.67, 3.75, 4.8
>>> abs(nums - [3, 2, 1, 1])

2, 0, 2, 3
>>> (nums * [2, 2, 1, 5] + [3, 5, 9, 0]) / [4, 1, 2, 3]

1, 9, 6, 6
>>> ((nums * itertools.repeat(2) + itertools.repeat(3)) /

itertools.repeat(4)).replicate([2, 2, 3, 3])
1, 0, 0, 0
>>> ((nums * [2, 3, 4, 5]) > [5, 6, 7, 8]) != [True, True, False, True]

True, True, True, False

The RecursiveElementwiseProxy:

>>> treenums = RecursiveElementwiseProxy([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> treenums + 1

((2, 3, 4), (5, 6, 7), (8, 9, 10))
>>> treenums * 2

((2, 4, 6), (8, 10, 12), (14, 16, 1)
>>> (treenums * 2 + 1).apply(float)

((3.0, 5.0, 7.0), (9.0, 11.0, 13.0), (15.0, 17.0, 19.0))


Feedback is welcome.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Elementwise -//- first release -//- Element-wise (vectorized)function, method and operator support for iterables in python. Nathan Rice Python 10 12-21-2011 05:22 PM
Re: Elementwise -//- first release -//- Element-wise (vectorized)function, method and operator support for iterables in python. Nathan Rice Python 4 12-21-2011 04:43 PM
FAQ 4.43 How do I compute the difference of two arrays? How do I compute the intersection of two arrays? PerlFAQ Server Perl Misc 0 02-02-2011 05:00 AM
filter iterable based on predicate take from another iterable bernhard.voigt@gmail.com Python 2 12-10-2008 10:44 AM
Tracking computation dependencies and lazily recomputing while caching results levy Java 0 08-28-2007 08:28 AM



Advertisments