Alan Gauld wrote:

"Wayne Watson" <sierra_mtnv...@sbcglobal.net> wrote

 Basically, what I would like to do is to take a list like:

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

and convert it to;
[['0x0', '0x1', '0x2', '0x3', '0x4'], ['0x5', '0x6', '0x7', '0x8', '0x9']]

What is the basis of this conversion?
Use of pyfits (FITS formats for astronomy) needs it this way.
Why did you split it into two lists?
Again, pyfits. It's a matrix/array (their version and used widely in math).
Why convert into hex strings?
Ultimately, I may have to do it for pyfits. I was preparing for it's use there, so it was convenient to use what I had. The "array" I constructed is the important thing. In math, arrays (matrices) are always of the form r*c*p*..., where those symbols are integers. r,c, p, ... represent dimensions. x,y,z for example.

If the original list had been:

[3, 5, 78, 21, -3,  7, 5]

What would your output look like?

There wouldn't be any. You have 7 elements. The first row of the matrix/table/array would be [3,4,78,21], and the second row would not contain the same # of elements.
That is, it becomes a matrix of 2 rows and 5 columns. I generated the above from a loop in Python, and generated hex equivalents in the last list.

It might help to see those loops because it might
explain the reasoning behind the apparently arbitrary
decisions.
Explained above.

Can numpy do this simply without resorting to loops?

Can't help there, I've never used numpy...

Well, the FITS and numpy guys (NASA) will be back today, so I'll work it out with them.

--
          Wayne Watson (Watson Adventures, Prop., Nevada City, CA)

            (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet All the neutrons, and protons in the human body occupy a cube whose is 5.52*10**-6 meters. That adds up to a 150 pound person. It's not a surprise that we are mostly space. (Calculation by WTW)



_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to