[Numpy-discussion] A question about dtype syntax

Jean-Baptiste Marquette marquett at iap.fr
Wed Aug 31 06:20:01 EDT 2011


Hi Pierre,

Thanks for the guess. Unfortunately, I got the same error:

[('bs3000k.cat', 280.60341, -7.09118, 9480, 0.2057, 0.14)]
Traceback (most recent call last):
  File "/Users/marquett/workspace/Distort/src/StatsSep.py", line 40, in <module>
    StatsAll = np.array(np.asarray(Stats), dtype=('a15, f8, f8, i4, f8, f8'))
ValueError: could not convert string to float: bs3000k.cat

The code is

Stats = [(CatBase, round(stats.mean(Data.Ra), 5), round(stats.mean(Data.Dec), 5), len(Sep), round(stats.mean(Sep),4), round(stats.stdev(Sep),4),)]
print Stats
if First:
    StatsAll = np.array(np.asarray(Stats), dtype=('a15, f8, f8, i4, f8, f8'))
    First = False
else: 
    StatsAll = np.vstack((StatsAll, np.asarray(Stats)))
    print len(StatsAll)

I tried various syntaxes, without success.

Cheers
JB


> 
> On Aug 30, 2011, at 10:46 AM, Marquette Jean-Baptiste wrote:
> 
>> Hi all,
>> 
>> I have this piece of code:
>> 
>> Stats = [CatBase, round(stats.mean(Data.Ra), 5), round(stats.mean(Data.Dec), 5), len(Sep), round(stats.mean(Sep),4), round(stats.stdev(Sep),4)]
>> print Stats
>> if First:
>> 	StatsAll = np.array(np.asarray(Stats), dtype=('a11, f8, f8, i4, f8, f8'))
>>        First = False
>> else: 
>>        StatsAll = np.vstack((StatsAll, np.asarray(Stats)))
>>        print len(StatsAll)
>> 
>> This yields the error:
>> 
>> ['bs3000k.cat', 280.60341, -7.09118, 9480, 0.2057, 0.14]
>> Traceback (most recent call last):
>>  File "/Users/marquett/workspace/Distort/src/StatsSep.py", line 40, in <module>
>>    StatsAll = np.array(np.asarray(Stats), dtype=('a11, f8, f8, i4, f8, f8'))
>> ValueError: could not convert string to float: bs3000k.cat
>> 
>> What's wrong ?
> 
> My guess:
> Stats is a list of 5 elements, but you want a list of 1 5-element tuple to match the type. 
> 
>> Stats = [(CatBase, round(stats.mean(Data.Ra), 5), round(stats.mean(Data.Dec), 5), len(Sep), round(stats.mean(Sep),4), round(stats.stdev(Sep),4),)]
> 
> 
> 
> 
> 
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110831/c7d5a997/attachment.html>


More information about the NumPy-Discussion mailing list