[Numpy-discussion] Using numpy's flatten_dtype with structured dtypes that have titles

Emma Willemsma emma.willemsma@morgansolar....
Mon Aug 23 09:50:59 CDT 2010


I have attached a short script and sample text file that demonstrate the
problem. The dtype I'm using in the example is:

dtype2 =
numpy.dtype([(("Amps","Current"),"f8"),(("Volts","Voltage"),"f8"),(("Watts","Power"),"f8")])

When I run the code as-is, I get the ValueError. If I run it with the monkey
patch, it runs as I would expect.

On the other hand, if I remove the titles from the dtype, the code works
with or without the monkey patch. Without the titles, the dtype looks like:

dtype1 = numpy.dtype([("Current","f8"),("Voltage","f8"),("Power","f8")])

Thanks very much for your help with this issue.

Emma



2010/8/23 Stéfan van der Walt <stefan@sun.ac.za>

> Hi Emma
>
> On 19 August 2010 23:07, Emma Willemsma <emma.willemsma@morgansolar.com>
> wrote:
> > I am working with structured arrays to store experimental data. I'm using
> > titles to store information about my fields, in this case the units of
> > measure. When I call numpy.lib.io.flatten_dtype() on my dtype, I get:
> >
> > ValueError: too many values to unpack
> > File "c:\Python25\Lib\site-packages\numpy\lib\_iotools.py", line 78, in
> > flatten_dtype
>
> Could you please provide an example of your dtype, or of your .txt
> file?  With such a test case, we should be able to make flatten_dtype
> more robust.
>
> > The user who responded suggested the following monkey-patch:
>
> Unfortunately, the monkey patch is aimed at addressing your issue
> only, so we won't be able to use it as is.
>
> Regards
> Stéfan
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100823/c9d2c0d7/attachment-0001.html 
-------------- next part --------------
1.000	-0.000	-0.000
0.990	0.356	0.352
0.980	0.409	0.401
0.970	0.440	0.427
0.960	0.462	0.444
0.950	0.479	0.455
0.940	0.493	0.464
0.930	0.505	0.470
0.920	0.515	0.474
0.910	0.524	0.477
0.900	0.533	0.479
0.890	0.540	0.480
0.880	0.547	0.481
0.870	0.553	0.481
0.860	0.558	0.480
0.850	0.564	0.479
0.840	0.569	0.478
0.830	0.573	0.476
0.820	0.578	0.474
0.810	0.582	0.471
0.800	0.586	0.469
0.790	0.590	0.466
0.780	0.593	0.463
0.770	0.597	0.459
0.760	0.600	0.456
0.750	0.603	0.452
0.740	0.606	0.449
0.730	0.609	0.445
0.720	0.612	0.441
0.710	0.615	0.436
0.700	0.617	0.432
0.690	0.620	0.428
0.680	0.622	0.423
0.670	0.624	0.418
0.660	0.627	0.414
0.650	0.629	0.409
0.640	0.631	0.404
0.630	0.633	0.399
0.620	0.635	0.394
0.610	0.637	0.389
0.600	0.639	0.384
0.590	0.641	0.378
0.580	0.643	0.373
0.570	0.645	0.368
0.560	0.647	0.362
0.550	0.648	0.357
0.540	0.650	0.351
0.530	0.652	0.345
0.520	0.653	0.340
0.510	0.655	0.334
0.500	0.656	0.328
0.490	0.658	0.322
0.480	0.660	0.317
0.470	0.661	0.311
0.460	0.662	0.305
0.450	0.664	0.299
0.440	0.665	0.293
0.430	0.667	0.287
0.420	0.668	0.281
0.410	0.669	0.274
0.400	0.671	0.268
0.390	0.672	0.262
0.380	0.673	0.256
0.370	0.674	0.249
0.360	0.676	0.243
0.350	0.677	0.237
0.340	0.678	0.230
0.330	0.679	0.224
0.320	0.680	0.218
0.310	0.681	0.211
0.300	0.682	0.205
0.290	0.684	0.198
0.280	0.685	0.192
0.270	0.686	0.185
0.260	0.687	0.179
0.250	0.688	0.172
0.240	0.689	0.165
0.230	0.690	0.159
0.220	0.691	0.152
0.210	0.692	0.145
0.200	0.693	0.139
0.190	0.694	0.132
0.180	0.695	0.125
0.170	0.696	0.118
0.160	0.696	0.111
0.150	0.697	0.105
0.140	0.698	0.098
0.130	0.699	0.091
0.120	0.700	0.084
0.110	0.701	0.077
0.100	0.702	0.070
0.090	0.703	0.063
0.080	0.703	0.056
0.070	0.704	0.049
0.060	0.705	0.042
0.050	0.706	0.035
0.040	0.707	0.028
0.030	0.708	0.021
0.020	0.708	0.014
0.010	0.709	0.007
1.000	0.000	0.000
1.000	0.007	0.007
1.000	0.014	0.014
0.999	0.021	0.021
0.999	0.028	0.028
0.999	0.035	0.035
0.999	0.043	0.043
0.999	0.050	0.050
0.998	0.057	0.057
0.998	0.064	0.064
0.998	0.071	0.071
0.998	0.078	0.078
0.998	0.085	0.085
0.997	0.092	0.092
0.997	0.099	0.099
0.997	0.106	0.106
0.997	0.114	0.113
0.997	0.121	0.120
0.996	0.128	0.127
0.996	0.135	0.134
0.996	0.142	0.141
0.996	0.149	0.148
0.996	0.156	0.155
0.995	0.163	0.163
0.995	0.170	0.170
0.995	0.177	0.177
0.995	0.185	0.184
0.995	0.192	0.191
0.994	0.199	0.198
0.994	0.206	0.205
0.994	0.213	0.212
0.994	0.220	0.219
0.994	0.227	0.226
0.993	0.234	0.233
0.993	0.241	0.240
0.993	0.248	0.247
0.993	0.256	0.254
0.993	0.263	0.261
0.992	0.270	0.268
0.992	0.277	0.275
0.992	0.284	0.282
0.992	0.291	0.289
0.992	0.298	0.296
0.991	0.305	0.303
0.991	0.312	0.310
0.991	0.319	0.317
0.991	0.327	0.324
0.991	0.334	0.331
0.990	0.341	0.337
0.990	0.348	0.344
0.990	0.355	0.351
0.989	0.362	0.358
0.987	0.369	0.365
0.986	0.376	0.371
0.985	0.383	0.378
0.983	0.390	0.384
0.982	0.398	0.390
0.981	0.405	0.397
0.979	0.412	0.403
0.977	0.419	0.409
0.974	0.426	0.415
0.972	0.433	0.421
0.970	0.440	0.427
0.967	0.447	0.432
0.963	0.454	0.438
0.960	0.461	0.443
0.956	0.469	0.448
0.952	0.476	0.453
0.947	0.483	0.457
0.942	0.490	0.462
0.937	0.497	0.466
0.931	0.504	0.469
0.924	0.511	0.472
0.917	0.518	0.475
0.909	0.525	0.477
0.900	0.532	0.479
0.890	0.540	0.480
0.880	0.547	0.481
0.868	0.554	0.481
0.855	0.561	0.480
0.842	0.568	0.478
0.826	0.575	0.475
0.810	0.582	0.471
0.791	0.589	0.466
0.771	0.596	0.460
0.749	0.603	0.452
0.725	0.611	0.442
0.698	0.618	0.431
0.669	0.625	0.418
0.637	0.632	0.402
0.602	0.639	0.385
0.563	0.646	0.364
0.521	0.653	0.341
0.475	0.660	0.314
0.425	0.667	0.283
0.369	0.674	0.249
0.308	0.682	0.210
0.241	0.689	0.166
0.168	0.696	0.117
0.088	0.703	0.062
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test5.py
Type: application/octet-stream
Size: 1060 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100823/c9d2c0d7/attachment-0001.obj 


More information about the NumPy-Discussion mailing list