about array,arange
Robert Kern
robert.kern at gmail.com
Sat Nov 12 08:46:12 EST 2005
Shi Mu wrote:
> On 11/12/05, Robert Kern <robert.kern at gmail.com> wrote:
>
>>Shi Mu wrote:
>>
>>>i got confused by the use of array and arange.
>>>arange get array and range get list, why we need the two different types?
>>
>>When you're asking questions about a third-party module, it's a good
>>idea to mention the module. In this case you're asking about scipy_core
>>(hopefully) or else numarray or Numeric.
>>
>>The answer to your question is that sometimes we need to get largish
>>arrays (not lists) of consecutive numbers quickly. array(range(N)) is
>>wasteful of memory and time because it has to create a list of Python
>>ints that are simply going to be thrown away once we're done converting
>>to the needed array.
>
> still not clear. can you give an example?
> Thanks! it is from numeric module (really confused by the documentation)
An example of what? How to use arange()? I can't explain it any more
clearly than the docstring does.
In [1]: from Numeric import arange
In [2]: arange?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function arange>
Namespace: Interactive
Docstring:
arange(start, stop=None, step=1, typecode=None)
Just like range() except it returns an array whose type can be
specified by the keyword argument typecode.
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list