Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
format dtype
#1
Hi, 
I am struggling with a very basic problem. While reading or writing a data file, some times I need to define the format... normally I can do it as dype = float, or dtype = 'U6' etc. however if there is several columns, like say 20, I do not want to write dype = float, float, float .... 20 times. But I am unable to write it in a format like float*20 or float,20...  I found that I can write (float,20), which gives no error. But then the data that I read takes all the entries as 1 column, instead of reading it as 20 separate columns. 
If I have confused the question, I am giving an example:
I want to read say a file like this 3 rows and 3 columns:

'cow'  'book'  'top'
'dog'  'pen'  'down'
'lion'  'paper'  'left'


The dtype = 'U4','U4','U4'  reads a matrix of 3 rows and 3 columns, where as dype = ('U4',3) reads 3 rows with 1 column in each row. 
Any suggestion is very welcome. Thanks in advance.
Reply
#2
What's a dtype? Are you using some sort of external library for reading files?
Reply
#3
Do you mean DWORD ? (As in C)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting data without showing dtype, name etc. tgottsc1 3 4,395 Jan-10-2021, 02:15 PM
Last Post: buran
  Dtype STR but output in Shell still int? johnjfk 6 2,272 Oct-04-2020, 01:34 PM
Last Post: johnjfk
  How to resolve numpy ValueError: dtype.descr Py_veeran 0 1,846 Aug-18-2020, 06:46 PM
Last Post: Py_veeran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020