Mathematica: reconstruct an arbitrary nested list after Flatten?

You obviously need to save some information about list structure, because Flatten{a,{b,c}}==Flatten{{a,b},c}.

You obviously need to save some information about list structure, because Flatten{a,{b,c}}==Flatten{{a,b},c}. If ArrayQexpr, then the list structure is given by Dimensionsexpr and you can reconstruct it with Partition. E.g.

Expr = {{a, b, c}, {d, e, f}}; dimensions = Dimensionsexpr {2,3} unflatten = FoldPartition, #1, ReverseDropdimensions, 1&; expr == unflatten @ Flattenexpr (The Partition man page actually has a similar example called unflatten. ) If expr is not an array, you can try this: expr = {a, {b, c}}; indexes = Module{i=0}, IfListQ#1, Map#0, #1, ++i& @expr {1, {2, 3}} slots = indexes /. {i_Integer -> Sloti} {#1, {#2, #3}} unflatten = FunctionReleaseslots {#1, {#2, #3}} & expr == unflatten @@ Flattenexpr.

Yes, I have used the first one a couple of times, but the second version is what I need -- and very nicely done! Using Slot0 for anonymous recursion never occurred to me :) Thanks. – Janus Feb 15 at 13:14 I just found out about Slot0 while writing this; it's under Neat Examples, obviously :) – aaz Feb 15 at 13:40 Is Release documented?

Can anyone guide me to some information? I am using Mma 7 (M. Trott, in 'Programming' says it is undocumented, but gives no further information, as far as I can see).

– TomD Feb 17 at 0:55 1 @TomD - Sort of. Here it works the same as Evaluate. – aaz Feb 17 at 1:30 @aaz Thanks for that – TomD Feb 17 at 14:00.

I am not sure what you are trying to do with Compile. It is used when you want to evaluate procedural or functional expressions very quickly on numerical values, so I don't think it is going to help here. If repeated calculations of Df,... are impeding your performance, you can precompute and store them with something like Tabledk=Df,{{x,y},k},{k,0,kk}; Then just call dk to get the kth derivative.

1 Thanks. I quite agree that I wouldn't need compile for the example case -- but I don't think anyone would thank me for posting the actual expression I'm working with :) My question is the first sentence, everything else is background. – Janus Feb 15 at 7:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions