For this assignment you will need to use NumPy to do some work on multi dimensional arrays. Attached is a file that has 125,000 integers ranging in value from 1 to 9999. They were randomly generated. They represent 3 dimensional cube of values.
The data is intended to be parsed as follows:
- Every 50 integers represents one row
- Every 50 rows represents one layer of the cube
- So the numbers at locations 0-2499 make up the first layer, 2500-4999 make up the 2nd and so on.
Here is an image of a cube that follows the same rules but is 3x3x3 so you can get an idea of what is going on. 0,0,0 is the upper left corner, 1 and 2 complete the first row, 3, 4 and 5 make up the next, 6, 7 and 8 make up the third row of the top layer.
The next layer starts at 9, then 10 and 11 make up the rest of that row (directly below 0, 1 and 2). A contiguous sub cube that is 2x2x2 might be 0,1, 3, 4, 9, 10, 12, 13. That would be the sub cube that has a corner at the origin.

You have two tasks:
- Consider every possible contiguous 3x3x3 cube within the larger 50x50x50 cube. Find the cube that has the greatest sum of the 27 elements that make it up. Print the sum of the elements of that sub cube. Also print the coordinate of the corner of the sub cube which is closest to the origin (that is the coordinate with the smallest x, y and z values).
- Consider every possible contiguous 10x10x10 cube within the larger 50x50x50 cube. Create a dictionary of the sub cubes that have the same sum in the elements that make it up. The dictionary key will be the sum and the dictionary values with be the list of cubes with the same sum using the coordinate of the corner of the sub cube which is closest to the origin (that is the coordinate with the smallest x, y and z values). Print the dictionary key and list of cube coordinates.
- Create a new array which is a 2d array. Each cell of this array should contain the sum of the of the 50 integers in the corresponding row. So the cell at (0,0) should contain the sums of integers 0-49. (0,1) should contain the sum of the integers at positions 50-99 and so on. The cell at (1,0) should contain the sum of the integers at positions 2500-2549. Use NumPy's default print method to print out this array. It will show the 9 cells in each corner of the 2d array.
Submit a single file named youronid_hw10.py (example: roberwen_hw10.py.) that 1) opens a file called "array-final.txt" in the current directory, 2) parses the contents and 3) prints out the above results based on the contents of that file. Assume it will always have 125,000 comma separated integers in it.
文件为TXT文件,文件截图如下
