0

I have this issue, I'm trying to build a 3D array where I need later to overwrite eg. [:,:,5] with a value from a 1D array. My arrays look like this in numpy:

3D:

[[[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]

 [[   0.  150.   10.  300.   25.    0.]
  [   1.   25.    2.   75.    7.    0.]
  [   4.    0.    0.    0.    0.    0.]
  [   5.    0.    0.    0.    0.    0.]]]

1D:

[ 1806.    1092.     150.     150.    2669.     150.     150.     150.
   310.    7181.85]

.. and what I want is this:

3d[0][0][5] = 1d[0]
3d[0][1][5] = 1d[0]
3d[0][2][5] = 1d[0]
3d[0][3][5] = 1d[0]
3d[1][0][5] = 1d[1]
3d[1][1][5] = 1d[1]
3d[1][2][5] = 1d[1]
3d[1][3][5] = 1d[1]

and so on. I have been trying somthing like this:

list_product_pricegroup[:,:,5] = migrete_array[:]

without any kind of luck, hope someone can guide me in the right direction.

1
  • can you update your code for array creation? please? Commented Feb 9, 2018 at 8:52

1 Answer 1

2

Your array list_product_pricegroup is 10x4x6 and migrete_array is a 1-D vector of 10. Since you index (5) the array list_product_pricegroup before assignment, it is now a 10x4 matrix. Then you need to promote migrete_array to a 2-D array of size 4x1 to be broadcasted, as such:

list_product_pricegroup[..., 5] = migrete_array[:, None]
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, its working close on what i want, but the numbers now going from [[ 0. 150. 10. 300. 25. 0.] [ 1. 25. 2. 75. 7. 0.] [ 4. 0. 0. 0. 0. 0.] [ 5. 0. 0. 0. 0. 0.]]] to [[ 0.00000000e+00 1.50000000e+02 1.00000000e+01 3.00000000e+02 2.50000000e+01 7.18185000e+03] [ 1.00000000e+00 2.50000000e+01 2.00000000e+00 7.50000000e+01 7.00000000e+00 7.18185000e+03]
yes, I thought this is how you wanted them to be, according to what I understood from the question
yes and no :), i want the value moved to the 5 inx and its true, if i do the same just type static number eg. 1000.0 its working fine, and around 50% work fine but som of the numbers not are moving currect there giving the funny numbers you see when i trying your code of, its only this migrete_array[:, None] part there make troblue now, orter are like this as is shut be [[ 0. 150. 10. 300. 25. 150.] [ 1. 25. 2. 75. 7. 150.] [ 4. 0. 0. 0. 0. 150.] [ 5. 0. 0. 0. 0. 150.]]
nevermind, its working i'm trying to print out print(list_product_pricegroup[9][3][5]) and its working as i shut be, thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.