sonettguy
Posts: 98
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

placing 2-dim arrays into 3-dim sheets

Wed Apr 17, 2019 2:22 pm

I need some help. I'm on a pi zero w with raspbian stretch and using python 2.7 and numpy. I'm building 2-dim arrays in a loop and would like to store each resulting array. So, I'd like to build a 3-dim array with each sheet being a loop iteration. I'm confused as to how to create the 3-D array and add elements as 2-D arrays. I refer to the manual, which states:
Indexing Multi-dimensional arrays
Things become more complex when multidimensional arrays are indexed, particularly with multidimensional index arrays. These tend to be more unusual uses, but they are permitted, and they are useful for some problems. We’ll start with the simplest multidimensional case (using the array y from the previous examples):
>>> y=np.arange(35).reshape(5,7) #I added this line from previous examples.
>>>
>>> y[np.array([0,2,4]), np.array([0,1,2])]
array([ 0, 15, 30])
In this case, if the index arrays have a matching shape, and there is an index array for each dimension of the array being indexed, the resultant array has the same shape as the index arrays, and the values correspond to the index set for each position in the index arrays. In this example, the first index value is 0 for both index arrays, and thus the first value of the resultant array is y[0,0]. The next value is y[2,1], and the last is y[4,2].
My code:

Code: Select all

for i in range(manifolds):
   for j in range(known):
      for k in range(new):
         {lots of stuff)
         print "resulting 2-D array",matmul.shape,matmul.dtype
         print matmul
         if i==0, j==0, k==0:
            correl=np.expand_dims(matmul, axis=0)
            print "correl is", correl.shape, correl.dtype
         correl(i,j,k)=correl.itemset(i, matmul[j,k])
I get

Code: Select all

   File "nameofprog.py", line 245
         correl(i,j,k)=correl.itemset(i,matmul[j,k])
SyntaxError: can't assign to function call
I don't see what is wrong.

sonettguy
Posts: 98
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

Re: placing 2-dim arrays into 3-dim sheets

Thu Apr 18, 2019 6:56 pm

I am wondering if I might have done something to alienate the forum. This is the third topic I've posted asking for help and not getting feedback. If I did something wrong, I apologize, I certainly didn't intend to offend anyone.

pcmanbob
Posts: 5469
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: placing 2-dim arrays into 3-dim sheets

Thu Apr 18, 2019 7:10 pm

As 99.9% of people here are just other pi users it my be that no one that has looked at your post has any idea on how to solve your problem.

It can take days for the right person to see your post, 24 hours is a very short time for that to occur.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

sonettguy
Posts: 98
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

Re: placing 2-dim arrays into 3-dim sheets

Thu Apr 18, 2019 7:55 pm

Good to know, @pcmanbob. Thanks.

Return to “Troubleshooting”