| Author |
Comment/Response |
Nasser M. Abbasi
|
06/29/12 07:29am
==========================
First, I have a multi-dimensional array (let's call it "array1") and I don't know a priori how many dimensions it has.
==========================
Use Dimensions[] to find the size
========================
Second, I have an address of some element of array1 and it looks like:
address1={2,2,1,5,3,1};
========================
These are called positions, or indices, not address. There are no pointers in Mathematica.
=======================
I know that I can extract this element using such code:
(array1[[##]] & @@@ {address1})[[1]]
=======================
I do not understand this code.
To read element at position pos from array A, simply type
A[[pos]]
============================
It will work just like "array1[[2,2,1,5,3,1]]". But the next line is not going to work:
(array1[[##]] & @@@ {address1})[[1]] = 15;
============================
To assign a value to a list at position pos type
A[[pos]=value
===================================
That is my question. How to change the value of an element of array1 which can be found using address1?
=====================================
Use [[ ]] Or Part.
If given position in pos, something like
Map[Part[A, Sequence @@ #] &, pos]
see my note on basic examples using Mathematica arrays here
http://12000.org/my_notes/mma_matlab_control/KERNEL/node66.htm
URL: , |
|