Data re-structure by Thread

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Thread can do this
Thread[a, b, c, d]
a, b, a, c, a, d
But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization
Thread[a, b, x, y, z, w, u, v]
which just raises an error.
Here what is intended for is
a, b, x, y, a, b, z, w, a, b, u, v
So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?
list-manipulation data data-structures
add a comment |Â
up vote
2
down vote
favorite
Thread can do this
Thread[a, b, c, d]
a, b, a, c, a, d
But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization
Thread[a, b, x, y, z, w, u, v]
which just raises an error.
Here what is intended for is
a, b, x, y, a, b, z, w, a, b, u, v
So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?
list-manipulation data data-structures
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Thread can do this
Thread[a, b, c, d]
a, b, a, c, a, d
But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization
Thread[a, b, x, y, z, w, u, v]
which just raises an error.
Here what is intended for is
a, b, x, y, a, b, z, w, a, b, u, v
So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?
list-manipulation data data-structures
Thread can do this
Thread[a, b, c, d]
a, b, a, c, a, d
But when above a, b, c and d are themselves Lists, for instance, used as a representation for 2D/3D points, it will not work as a naive generalization
Thread[a, b, x, y, z, w, u, v]
which just raises an error.
Here what is intended for is
a, b, x, y, a, b, z, w, a, b, u, v
So can it still be realized by Thread? If yes, how? If no, then do there exist any concise and efficient workarounds?
list-manipulation data data-structures
list-manipulation data data-structures
asked 2 hours ago
ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1,723720
1,723720
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
A level specification can help (we have to specify the head to thread over, too):
Thread[a, b, x, y, z, w, u, v, List, 2]
a, b, x, y, a, b, z, w, a, b, u, v
Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:
Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2],
List, 2] // Developer`PackedArrayQ // AbsoluteTiming
Transpose[
ConstantArray[RandomReal[-1, 1, 2], 1000000],
RandomReal[-1, 1, 1000000, 2]
] // Developer`PackedArrayQ // AbsoluteTiming
0.347755, False
0.046035, True
It seems it. So any clarification for the curly brackets around2here? The F1 documentation ofThreaddoes not mention level specification.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
For level specifications,f[...,n]with integernusually means "until leveln" whilef[...,n]means "only at leveln".
â Henrik Schumacher
2 hours ago
1
Sorry, do you meanf[..., n]in the latter?
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
A level specification can help (we have to specify the head to thread over, too):
Thread[a, b, x, y, z, w, u, v, List, 2]
a, b, x, y, a, b, z, w, a, b, u, v
Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:
Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2],
List, 2] // Developer`PackedArrayQ // AbsoluteTiming
Transpose[
ConstantArray[RandomReal[-1, 1, 2], 1000000],
RandomReal[-1, 1, 1000000, 2]
] // Developer`PackedArrayQ // AbsoluteTiming
0.347755, False
0.046035, True
It seems it. So any clarification for the curly brackets around2here? The F1 documentation ofThreaddoes not mention level specification.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
For level specifications,f[...,n]with integernusually means "until leveln" whilef[...,n]means "only at leveln".
â Henrik Schumacher
2 hours ago
1
Sorry, do you meanf[..., n]in the latter?
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
up vote
3
down vote
accepted
A level specification can help (we have to specify the head to thread over, too):
Thread[a, b, x, y, z, w, u, v, List, 2]
a, b, x, y, a, b, z, w, a, b, u, v
Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:
Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2],
List, 2] // Developer`PackedArrayQ // AbsoluteTiming
Transpose[
ConstantArray[RandomReal[-1, 1, 2], 1000000],
RandomReal[-1, 1, 1000000, 2]
] // Developer`PackedArrayQ // AbsoluteTiming
0.347755, False
0.046035, True
It seems it. So any clarification for the curly brackets around2here? The F1 documentation ofThreaddoes not mention level specification.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
For level specifications,f[...,n]with integernusually means "until leveln" whilef[...,n]means "only at leveln".
â Henrik Schumacher
2 hours ago
1
Sorry, do you meanf[..., n]in the latter?
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
A level specification can help (we have to specify the head to thread over, too):
Thread[a, b, x, y, z, w, u, v, List, 2]
a, b, x, y, a, b, z, w, a, b, u, v
Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:
Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2],
List, 2] // Developer`PackedArrayQ // AbsoluteTiming
Transpose[
ConstantArray[RandomReal[-1, 1, 2], 1000000],
RandomReal[-1, 1, 1000000, 2]
] // Developer`PackedArrayQ // AbsoluteTiming
0.347755, False
0.046035, True
A level specification can help (we have to specify the head to thread over, too):
Thread[a, b, x, y, z, w, u, v, List, 2]
a, b, x, y, a, b, z, w, a, b, u, v
Note that this unpacks arrays, so I would not suggest that for big datasets. I that case, I would suggest as ConstantArray/`Transpose combo:
Thread[RandomReal[-1, 1, 2], RandomReal[-1, 1, 1000000, 2],
List, 2] // Developer`PackedArrayQ // AbsoluteTiming
Transpose[
ConstantArray[RandomReal[-1, 1, 2], 1000000],
RandomReal[-1, 1, 1000000, 2]
] // Developer`PackedArrayQ // AbsoluteTiming
0.347755, False
0.046035, True
edited 2 hours ago
answered 2 hours ago
Henrik Schumacher
38.2k250110
38.2k250110
It seems it. So any clarification for the curly brackets around2here? The F1 documentation ofThreaddoes not mention level specification.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
For level specifications,f[...,n]with integernusually means "until leveln" whilef[...,n]means "only at leveln".
â Henrik Schumacher
2 hours ago
1
Sorry, do you meanf[..., n]in the latter?
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
It seems it. So any clarification for the curly brackets around2here? The F1 documentation ofThreaddoes not mention level specification.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
For level specifications,f[...,n]with integernusually means "until leveln" whilef[...,n]means "only at leveln".
â Henrik Schumacher
2 hours ago
1
Sorry, do you meanf[..., n]in the latter?
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
It seems it. So any clarification for the curly brackets around
2 here? The F1 documentation of Thread does not mention level specification.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
It seems it. So any clarification for the curly brackets around
2 here? The F1 documentation of Thread does not mention level specification.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
1
For level specifications,
f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".â Henrik Schumacher
2 hours ago
For level specifications,
f[...,n] with integer n usually means "until level n" while f[...,n] means "only at level n".â Henrik Schumacher
2 hours ago
1
1
Sorry, do you mean
f[..., n] in the latter?â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
Sorry, do you mean
f[..., n] in the latter?â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
2 hours ago
1
1
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
Yes. But I fixed the comment already. Thanks for the accept btw.
â Henrik Schumacher
2 hours ago
1
1
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
Your information on packed array is valuable.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f182022%2fdata-re-structure-by-thread%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
