Message Boards Message Boards

0
|
4062 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Use a vector as tensor argument?

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.

POSTED BY: damiano capocci
3 Replies
Posted 5 years ago

Same question was asked on MSE.

POSTED BY: Rohit Namjoshi

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

POSTED BY: damiano capocci

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
POSTED BY: Hans Dolhaine
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