Message Boards Message Boards

GROUPS:

Use a vector as tensor argument?

Posted 9 days ago
119 Views
|
3 Replies
|
1 Total Likes
|

Good morning,

I want to assign a certain value to an element of a tensor. This element is identified by an array obtained from some evaluations, so we fix it. Here i present an oversimplified core part of my code:

DimensionA = 3;
v = {1, 2, 3};
Array[TensorA, Table[10, DimensionA], 0];  
TensorA @@ v = 12;

at this point i receive an error

Set::write: Tag Apply in TensorA@@{1,2,3} is Protected.

Obviously if i do TensorA[1, 2, 3] = 12;it is all ok but my aim is to give in input a vector with an arbitrary number of indices. Let me know how should I give in input the vector to the tensor without receiving this error.

Please admins don't remove this question.

3 Replies

Do you mean this?

In[1]:= DimensionA = 3;
v = {1, 2, 3};
Array[TensorA, Table[10, {DimensionA}], 0];
TensorA[Sequence @@ v] = 12

Out[4]= 12


In[5]:= TensorA[1, 2, 3]

Out[5]= 12

Yes exactly, i didn't know about the expression [Sequence @@ ]. Thank you for the answer.

Same question was asked on MSE.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract