Message Boards Message Boards

GROUPS:

Create 3D array from a 2D matrix?

Posted 10 days ago
78 Views
|
1 Reply
|
2 Total Likes
|

I have a matrix ,e.g., d2={{3,2},{4,1},{5,6}}, and I want to create a 3D array, e.g., d3={{3,18,2},{4,32,1},{5,50,6}} from the 2D matrix, note that the inserted middle element is 2 times the square of the first element . I can not figure out how to do this in mathematica

In[1]:= d = {{3, 2}, {4, 1}, {5, 6}};

In[2]:= d /. {a_, b_} -> {a, 2*a^2, b}

Out[2]= {{3, 18, 2}, {4, 32, 1}, {5, 50, 6}}
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