Matthieu Brucher wrote:
> And if there is a way to add a
> formatting option ('1.1f' for instance), it would be
> even better.
For full control of the formatting, you can use python's string
formatting, and a nested list comprehension:
[ ["%.3f"%i
Thank you for the precision, I didn't thought of using 'Sxx' directly :(
Matthieu
2007/10/5, lorenzo bolla <[EMAIL PROTECTED]>:
>
> gotcha. specify the number of bytes, then.
>
> In [20]: x
> Out[20]:
> array([[-2., 3.],
>[ 4., 5.]])
>
> In [21]: x.astype(numpy.dtype('S10'))
> Out[21]:
gotcha. specify the number of bytes, then.
In [20]: x
Out[20]:
array([[-2., 3.],
[ 4., 5.]])
In [21]: x.astype(numpy.dtype('S10'))
Out[21]:
array([['-2.0', '3.0'],
['4.0', '5.0']],
dtype='|S10')
L.
On 10/5/07, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
>
> I'd like to hav
On 05/10/2007, Matthieu Brucher <[EMAIL PROTECTED]> wrote:
> I'd like to have the '2.', because if the number is negative, only '-' is
> returned, not the real value.
For string arrays you need to specify the length of the string as part
of the data type (and it defaults to length 1):
In [11]: ra
I'd like to have the '2.', because if the number is negative, only '-' is
returned, not the real value.
Matthieu
2007/10/5, lorenzo bolla <[EMAIL PROTECTED]>:
>
> what's wrong with astype?
>
> In [3]: x = numpy.array([[2.,3.],[4.,5.]])
>
> In [4]: x.astype(str)
> Out[4]:
> array([['2', '3'],
>
what's wrong with astype?
In [3]: x = numpy.array([[2.,3.],[4.,5.]])
In [4]: x.astype(str)
Out[4]:
array([['2', '3'],
['4', '5']],
dtype='|S1')
and if you want a list:
In [5]: x.astype(str).tolist()
Out[5]: [['2', '3'], ['4', '5']]
L.
On 10/5/07, Matthieu Brucher <[EMAIL PROTEC
Hi,
I'm trying to cast a float array into a string array (for instance
transforming [[2., 3.], [4., 5.]] into [['2.', '3.'], ['4.', '5.']]), I
tried with astype(str) and every variation (str_, string, string_, string0),
but not luck.
Is there a function or a method of the array class that can fulf