On Mon, Oct 20, 2008 at 2:06 PM, pong <[EMAIL PROTECTED]> wrote:
>
> Thanks Marshall. I have thought about that as well.
> Since I want to optimize time. I want to see if your method is faster
> then a for loop. However, I run into something puzzling:
>
> vector( [k for k in range(10)]) results in an error. Sage compliant
> about
>
> TypeError: unable to find a common ring for all elements

I get

sage: vector( [k for k in range(10)])
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Are you sure that's what you typed?

>
> But if you check each element of the list, I got <type 'int'>
>
> So why SAGE is complaining?
>
> On Oct 19, 7:27 am, Marshall Hampton <[EMAIL PROTECTED]> wrote:
>> Another option is to convert your list to a vector, and then convert
>> it back.  This is more awkward for a single operation but if you are
>> doing lots of vector addition and scalar multiplication it can be the
>> way to go.
>> I.e. you can do:
>>
>> sage: a = [3,4]
>> sage: a = list(2*vector(a))
>> sage: a
>> [6, 8]
>>
>> -M. Hampton
>>
>> On Oct 19, 1:15 am, Robert Bradshaw <[EMAIL PROTECTED]>
>> wrote:
>>
>> > On Oct 18, 2008, at 10:14 PM, Alex Ghitza wrote:
>>
>> > > Hmmm.  As far as I know you can use _ as a placeholder for a
>> > > variable, and it's meant for this kind of use (where you don't
>> > > really want to introduce a new variable name).  It's strange that
>> > > it doesn't work for you.  Can you post the error message that you get?
>>
>> > Actually, _ is an actual variable, though personally I find it a bit
>> > harder to read than a normal letter. The one special thing about it
>> > (in ipython at least) is that it constantly gets reassigned to the
>> > last returned value, e.g.
>>
>> > sage: 1+2
>> > 3
>> > sage: _
>> > 3
>>
>> > - Robert
> >
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to