Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Dealing with irregular shaped arrays

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22052] RE: [mg22018] Dealing with irregular shaped arrays
  • From: French Christopher Lee <frenchc at tce.com>
  • Date: Fri, 11 Feb 2000 02:38:34 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Steve,

Import ragged array, pad to a regular array. OK.


Your ReadList["ragged.txt", Number, RecordLists -> True] is good but do not
be fooled by TableForm. It is a display form and not really altering your
data structure.

ragged = ReadList["ragged.txt", Number, RecordLists -> True]

start by capturing the numerical data then create a structure that specifies
the element positions in the target matrix.

columndata = {{1, 2, 5}, {1, 2, 3, 4, 5}, {2, 3}, {1, 2, 3, 5}, {1, 4, 5}}

(please forgive the unusual programming style)

fivebyfive = 
{a, b, c, d, e} =
{ragged, columndata} 
 // Transpose 
 // Transpose /@ # &
 // Fold[ReplacePart[#1, Sequence @@ #2] &, Table["N/A", {5}], #] & /@ # &

Instead of inserting "N/A"'s this is like starting with all "N/A"'s and
replacing elements with data.

If you are fortunate enough to have the TABS in your file doing the
positioning for you then you can use them as word separators and keep them
in the input by specifying TokenWords.

ReadList["ragged.txt", Word, TokenWords -> {"\t"}, RecordLists -> True]


Christopher Lee French
<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>
Engineering Specialist
Department 661 Tube Design
TTD Engineering - Lancaster
Tel:(717) 295 2991. Fax:(717) 295 6045



  • Prev by Date: Re: formula for Pi
  • Next by Date: Re: formula for Pi
  • Previous by thread: Re: Mathlink and packed arrays
  • Next by thread: Re: Dealing with irregular shaped arrays