How do I allocate an array of vectors? [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I'm trying to follow the code posted by a user on Stack Exchange and I'm having trouble with an allocation of a matrix. The code is:
dim = 3;
XX = Table[X[[i]], i, dim];
and it's supposed to create an array of:
X[[1]], X[[2]], X[[3]]
And it does, but I get the following warnings:
Part::partd: Part specification X[[1]] is longer than depth of object. >>
Part::partd: Part specification X[[2]] is longer than depth of object. >>
Part::partd: Part specification X[[3]] is longer than depth of object. >>
General::stop: Further output of Part::partd will be suppressed during this calculation. >>
What's the proper way to allocate this matrix without the warnings?
matrix
closed as unclear what you're asking by Szabolcs, José Antonio DÃaz Navas, bbgodfrey, Bob Hanlon, gwr Sep 11 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |Â
up vote
1
down vote
favorite
I'm trying to follow the code posted by a user on Stack Exchange and I'm having trouble with an allocation of a matrix. The code is:
dim = 3;
XX = Table[X[[i]], i, dim];
and it's supposed to create an array of:
X[[1]], X[[2]], X[[3]]
And it does, but I get the following warnings:
Part::partd: Part specification X[[1]] is longer than depth of object. >>
Part::partd: Part specification X[[2]] is longer than depth of object. >>
Part::partd: Part specification X[[3]] is longer than depth of object. >>
General::stop: Further output of Part::partd will be suppressed during this calculation. >>
What's the proper way to allocate this matrix without the warnings?
matrix
closed as unclear what you're asking by Szabolcs, José Antonio DÃaz Navas, bbgodfrey, Bob Hanlon, gwr Sep 11 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
IfX
has no parts, you can not usePart
on it.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
1
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to follow the code posted by a user on Stack Exchange and I'm having trouble with an allocation of a matrix. The code is:
dim = 3;
XX = Table[X[[i]], i, dim];
and it's supposed to create an array of:
X[[1]], X[[2]], X[[3]]
And it does, but I get the following warnings:
Part::partd: Part specification X[[1]] is longer than depth of object. >>
Part::partd: Part specification X[[2]] is longer than depth of object. >>
Part::partd: Part specification X[[3]] is longer than depth of object. >>
General::stop: Further output of Part::partd will be suppressed during this calculation. >>
What's the proper way to allocate this matrix without the warnings?
matrix
I'm trying to follow the code posted by a user on Stack Exchange and I'm having trouble with an allocation of a matrix. The code is:
dim = 3;
XX = Table[X[[i]], i, dim];
and it's supposed to create an array of:
X[[1]], X[[2]], X[[3]]
And it does, but I get the following warnings:
Part::partd: Part specification X[[1]] is longer than depth of object. >>
Part::partd: Part specification X[[2]] is longer than depth of object. >>
Part::partd: Part specification X[[3]] is longer than depth of object. >>
General::stop: Further output of Part::partd will be suppressed during this calculation. >>
What's the proper way to allocate this matrix without the warnings?
matrix
matrix
asked Sep 5 at 0:26
Donald Airey
1677
1677
closed as unclear what you're asking by Szabolcs, José Antonio DÃaz Navas, bbgodfrey, Bob Hanlon, gwr Sep 11 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by Szabolcs, José Antonio DÃaz Navas, bbgodfrey, Bob Hanlon, gwr Sep 11 at 10:55
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, itâÂÂs hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
IfX
has no parts, you can not usePart
on it.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
1
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57
add a comment |Â
1
IfX
has no parts, you can not usePart
on it.
â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
1
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57
1
1
If
X
has no parts, you can not use Part
on it.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
If
X
has no parts, you can not use Part
on it.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
1
1
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
6
down vote
Not sure for what you are going to use this for, but I use things like XX = Table[X[[i]], i, dim];
frequently for symbolic preprocessing code for Compile
. In that case, Array[X, dim]
won't work.
You can ignore the warning with XX = Quiet[Table[X[[i]], i, dim]];
or you can use XX = Table[Indexed[X,i], i, dim];
instead.
As I found out only recently, Compile
is clever enough to substitute Indexed
by Part
as can be seen in the following example:
dim = 3;
XX = Table[Indexed[X, i], i, dim];
cDf = With[code = D[Sin[XX[[1]]] + XX[[2]]^3, XX, 1],
Compile[X, _Real, 1, code, CompilationTarget -> "C"]
];
CompiledFunctionTools`CompilePrint[cDf]
That's a useful trick (theIndexed
). I never knew that one.
â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
add a comment |Â
up vote
2
down vote
How about this
dim = 3;
Array[X, dim]
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
6
down vote
Not sure for what you are going to use this for, but I use things like XX = Table[X[[i]], i, dim];
frequently for symbolic preprocessing code for Compile
. In that case, Array[X, dim]
won't work.
You can ignore the warning with XX = Quiet[Table[X[[i]], i, dim]];
or you can use XX = Table[Indexed[X,i], i, dim];
instead.
As I found out only recently, Compile
is clever enough to substitute Indexed
by Part
as can be seen in the following example:
dim = 3;
XX = Table[Indexed[X, i], i, dim];
cDf = With[code = D[Sin[XX[[1]]] + XX[[2]]^3, XX, 1],
Compile[X, _Real, 1, code, CompilationTarget -> "C"]
];
CompiledFunctionTools`CompilePrint[cDf]
That's a useful trick (theIndexed
). I never knew that one.
â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
add a comment |Â
up vote
6
down vote
Not sure for what you are going to use this for, but I use things like XX = Table[X[[i]], i, dim];
frequently for symbolic preprocessing code for Compile
. In that case, Array[X, dim]
won't work.
You can ignore the warning with XX = Quiet[Table[X[[i]], i, dim]];
or you can use XX = Table[Indexed[X,i], i, dim];
instead.
As I found out only recently, Compile
is clever enough to substitute Indexed
by Part
as can be seen in the following example:
dim = 3;
XX = Table[Indexed[X, i], i, dim];
cDf = With[code = D[Sin[XX[[1]]] + XX[[2]]^3, XX, 1],
Compile[X, _Real, 1, code, CompilationTarget -> "C"]
];
CompiledFunctionTools`CompilePrint[cDf]
That's a useful trick (theIndexed
). I never knew that one.
â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
add a comment |Â
up vote
6
down vote
up vote
6
down vote
Not sure for what you are going to use this for, but I use things like XX = Table[X[[i]], i, dim];
frequently for symbolic preprocessing code for Compile
. In that case, Array[X, dim]
won't work.
You can ignore the warning with XX = Quiet[Table[X[[i]], i, dim]];
or you can use XX = Table[Indexed[X,i], i, dim];
instead.
As I found out only recently, Compile
is clever enough to substitute Indexed
by Part
as can be seen in the following example:
dim = 3;
XX = Table[Indexed[X, i], i, dim];
cDf = With[code = D[Sin[XX[[1]]] + XX[[2]]^3, XX, 1],
Compile[X, _Real, 1, code, CompilationTarget -> "C"]
];
CompiledFunctionTools`CompilePrint[cDf]
Not sure for what you are going to use this for, but I use things like XX = Table[X[[i]], i, dim];
frequently for symbolic preprocessing code for Compile
. In that case, Array[X, dim]
won't work.
You can ignore the warning with XX = Quiet[Table[X[[i]], i, dim]];
or you can use XX = Table[Indexed[X,i], i, dim];
instead.
As I found out only recently, Compile
is clever enough to substitute Indexed
by Part
as can be seen in the following example:
dim = 3;
XX = Table[Indexed[X, i], i, dim];
cDf = With[code = D[Sin[XX[[1]]] + XX[[2]]^3, XX, 1],
Compile[X, _Real, 1, code, CompilationTarget -> "C"]
];
CompiledFunctionTools`CompilePrint[cDf]
answered Sep 5 at 5:26
Henrik Schumacher
38.5k253114
38.5k253114
That's a useful trick (theIndexed
). I never knew that one.
â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
add a comment |Â
That's a useful trick (theIndexed
). I never knew that one.
â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
That's a useful trick (the
Indexed
). I never knew that one.â b3m2a1
Sep 5 at 6:55
That's a useful trick (the
Indexed
). I never knew that one.â b3m2a1
Sep 5 at 6:55
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
@b3m2a1 Yeah, me neither. =D
â Henrik Schumacher
Sep 5 at 9:29
add a comment |Â
up vote
2
down vote
How about this
dim = 3;
Array[X, dim]
add a comment |Â
up vote
2
down vote
How about this
dim = 3;
Array[X, dim]
add a comment |Â
up vote
2
down vote
up vote
2
down vote
How about this
dim = 3;
Array[X, dim]
How about this
dim = 3;
Array[X, dim]
answered Sep 5 at 2:57
ÃÂûÃÂþñýôÃÂÿàÃÂõóó
1,852721
1,852721
add a comment |Â
add a comment |Â
1
If
X
has no parts, you can not usePart
on it.â ÃÂûÃÂþñýôÃÂÿàÃÂõóó
Sep 5 at 2:55
1
In Mathematica there is almost never a need to pre-allocate an array. What are you actually trying to do?
â Szabolcs
Sep 5 at 7:57