[Numpy-discussion] Syntax equivalent for np.array()

josef.pktd@gmai... josef.pktd@gmai...
Wed Feb 10 10:40:10 CST 2010


On Wed, Feb 10, 2010 at 11:24 AM, Gökhan Sever <gokhansever@gmail.com> wrote:
>
>
> On Wed, Feb 10, 2010 at 10:12 AM, Gökhan Sever <gokhansever@gmail.com>
> wrote:
>>
>>
>> On Wed, Feb 10, 2010 at 10:06 AM, Angus McMorland <amcmorl@gmail.com>
>> wrote:
>>>
>>> On 10 February 2010 11:02, Gökhan Sever <gokhansever@gmail.com> wrote:
>>> > Hi,
>>> >
>>> > Simple question:
>>> >
>>> > I[4]: a = np.arange(10)
>>> >
>>> > I[5]: b = np.array(5)
>>> >
>>> > I[8]: a*b.cumsum()
>>> > O[8]: array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45])
>>> >
>>> > I[9]: np.array(a*b).cumsum()
>>> > O[9]: array([  0,   5,  15,  30,  50,  75, 105, 140, 180, 225])
>>> >
>>> > Is there a syntactic equivalent for the I[9] --for instance instead of
>>> > using
>>> > "list" keyword I use [ ] while creating a list. Is there a shortcut for
>>> > np.array instead of writing np.array(a*b) explicitly?
>>>
>>> How about just (a*b).cumsum() ?
>>>
>>> Angus.
>>> --
>>> AJC McMorland
>>> Post-doctoral research fellow
>>> Neurobiology, University of Pittsburgh
>>> _______________________________________________
>>> NumPy-Discussion mailing list
>>> NumPy-Discussion@scipy.org
>>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>> Yep that's it :) I knew that it was a very simple question.
>>
>> What confused me is I remember somewhere not sure maybe in IPython dev I
>> have gotten when I do:
>>
>> (a*b).cumsum()
>>
>> AttributeError: 'tuple' object has no attribute 'cumsum' error.
>>
>> So I was thinking ( ) is a ssugar for tuple and np.array might have
>> something special than these.
>>
>> --
>> Gökhan
>
> Self-correction:
>
> It works correctly in IPython-dev as well.
>
> And further in Python 2.6.2:
>
>>>> p = ()
>>>> p
> ()
>>>> type(p)
> <type 'tuple'>
>>>> type((a*b))
> <type 'numpy.ndarray'>
>
> ( ) doesn't only works as a tuple operator. It also has its original
> parenthesis functionality :)

except for empty tuple constructor, a comma defines a tuple and
parenthesis are just  parenthesis

>>> type((a*b))
<type 'numpy.ndarray'>
>>> type((a*b,))
<type 'tuple'>
>>> a*b,
(array([0, 1]),)
>>> type(_)
<type 'tuple'>

Josef


>
> --
> Gökhan
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>


More information about the NumPy-Discussion mailing list