I want to convert a one-dimensional array x to a three-dimensional array y as shown below.
x is an array containing 0-9215.
I want to extract this array x by 8 and store it in the depth direction of the array y of 256 × 6 × 6.
For example, store x [0: 8] in y [0: 8,0,0], store x [9:16] in y [0: 8,0,1], and store y [0: 8,6]. Up to, 6]
After storing, I want to store from y [8: 16,0,0] to y [8: 16,6,6].
I created a program with a for statement, but it took a long time to repeat the calculation.
I asked if you can speed up with numpy's reshape etc.
The program in the for statement is as follows.
import numpy as np x = np.arange (1152 * 16) print (x) y = np.zeros ((256,6,6)) for k in range (32): for i in range (6): for j in range (6): y [8 * k: 8 * (k + 1), i, j] = x [k * 8 * 36 + (i + j) * 8: k * 8 * 36 + (i + j + 1) * 8 ] print (y)
Answer # 1
You can reshape it to 4 dimensions, rearrange the dimensions with transpose, and then reshape it to the desired shape.
y = x [: 256 * 6 * 6] .reshape ((32, 6, 6, 8)). transpose ((0, 3, 1, 2)). Reshape ((256, 6, 6))
Imagine how the original array was split and rearranged.
- python - i want to calculate matrix calculation with numpy for statement with numpydot
- python - numpy import
- about writing if statements in dictionaries with python
- i want to speed up the processing of [python] for
- python - i want to store a 3d array in an array using numpy
- the calculation result of python print (1/2) becomes 0
- python i want to save a large amount of data at high speed
- python - saving the calculation result of the correlation coefficient
- about the interpretation of if statements in python
- python - comparison of reading speed of a large number of json formats
- i want to automatically generate a calculation problem in python
- numpy - [python] i want to combine alternately and make two sets of two arrays of latitude and longitude
- python - i have numpy installed, but i get an error saying "exp: unknown"
- python polygon area calculation can't assign to operator
- python 3x - how to remove 0 elements in numpy 2darray
- python - compare dictionary elements with if statements
- error when performing numerical calculation with python
- python 3x - about array calculation in python
- i want to initialize a string with python numpy
- python : The program with a neural network does not work
- Function is performed infinitely python
- python : NUMPY: How to replace rare numbers in the array on -1?
- python : NUMPY: How to replace certain indexes in the array on indexes in increasing in increments of 1
- python : Building a picture from an array
- python : NUMPY: Find a rectangle diagonal center in a two-dimensional array
- python : Replacing repetitive indexes to new
- python : NUMPY: How to flip the array along the axis
- python : NUMPY: Sorting a two-dimensional column array
- Selection of terms in NUMPY on Python