Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flatten lacks some functionality #251

Closed
wolfv opened this issue Jun 11, 2015 · 4 comments
Closed

Flatten lacks some functionality #251

wolfv opened this issue Jun 11, 2015 · 4 comments

Comments

@wolfv
Copy link
Member

wolfv commented Jun 11, 2015

I just coded some list functionality for Mathics, and noticed that unfortunately Flatten seems to lack some functionality:

>> Flatten[{{1,2,3}, {4,5,6}, {7,8,9}}] 
 = {1, 2, 3, 4, 5, 6, 7, 8, 9} // Correct!
>> Flatten[{{1,2,3}, {4,5,6}, {7,8,9}}, {2}]
: Level to be flattened together in {2} should be a non-negative integer.
Out[2]= Flatten[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {2}, List]

Expected Result:
{{1,4,7},{2,5,8},{3,6,9}}

I tried to fix it but couldn't wrap my head completely around where the issue exactly is. Flatten seems to be a pretty generic function in Mathics.

Otherwise, cool stuff!

Wolf

@sn6uv
Copy link
Member

sn6uv commented Jun 12, 2015

The way Mathics evaluation works is rules are applied first. The Flatten[expr_, n_] -> Flatten[expr, n, List] rule is being applied but {2} is not an integer so Mathics doesn't know what to do and reports an error.

@wolfv
Copy link
Member Author

wolfv commented Jun 12, 2015

Is there another Wolfram Language Spec this was based on? Because with the latest, "my" syntax should work.

Also, could you show me how to flatten the second dimension? I wasn't able to find another way to do it (ie. I tried: Flatten[{{1,2,3}, {4,5,6}}, 1, {2}] )

@sn6uv
Copy link
Member

sn6uv commented Jun 12, 2015

I'm reading through the online docs trying to get my head around what Flatten is spposed to do when the second argument is a list.

@wolfv
Copy link
Member Author

wolfv commented Jun 12, 2015

Let me know if I can be of any help.

As I understand, the list contains dimensions along which to flatten.

cf: selection_087

@sn6uv sn6uv mentioned this issue Jun 12, 2015
sn6uv added a commit to sn6uv/Mathics that referenced this issue Jun 20, 2015
@wolfv wolfv closed this as completed Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants