Skip to main content
added 6 characters in body
Source Link
Sjoerd Smit
  • 25.7k
  • 51
  • 85

In this situation, the most concise way to do what you want that I can think of is:

With[{part := Part[list, row - 1 ;; row + 1, start ;; start + 2]}, part = Array[color1 &ConstantArray[color1, Most @ Dimensions[part]] ] 

In short, just create a complete array that matches the dimensions of the Part your trying to overwrite. You're trying to overwrite a part of list with dimensions 3x3x3 with a list that has dimensions 3. That's why Mathematica does the assignment at a different level than you expect. The only way out of this is to match the dimensions of the old part and the new one.

In this situation, the most concise way to do what you want that I can think of is:

With[{part := Part[list, row - 1 ;; row + 1, start ;; start + 2]}, part = Array[color1 &, Most @ Dimensions[part]] ] 

In short, just create a complete array that matches the dimensions of the Part your trying to overwrite. You're trying to overwrite a part of list with dimensions 3x3x3 with a list that has dimensions 3. That's why Mathematica does the assignment at a different level than you expect. The only way out of this is to match the dimensions of the old part and the new one.

In this situation, the most concise way to do what you want that I can think of is:

With[{part := Part[list, row - 1 ;; row + 1, start ;; start + 2]}, part = ConstantArray[color1, Most @ Dimensions[part]] ] 

In short, just create a complete array that matches the dimensions of the Part your trying to overwrite. You're trying to overwrite a part of list with dimensions 3x3x3 with a list that has dimensions 3. That's why Mathematica does the assignment at a different level than you expect. The only way out of this is to match the dimensions of the old part and the new one.

Source Link
Sjoerd Smit
  • 25.7k
  • 51
  • 85

In this situation, the most concise way to do what you want that I can think of is:

With[{part := Part[list, row - 1 ;; row + 1, start ;; start + 2]}, part = Array[color1 &, Most @ Dimensions[part]] ] 

In short, just create a complete array that matches the dimensions of the Part your trying to overwrite. You're trying to overwrite a part of list with dimensions 3x3x3 with a list that has dimensions 3. That's why Mathematica does the assignment at a different level than you expect. The only way out of this is to match the dimensions of the old part and the new one.