Issue
I have some 3D structured array data and i want to process them into colormaps.
The array is very huge, and it looks like below when i print it.
[[[9.24908975e-05 9.24908975e-05 9.24908975e-05 ... 9.52468407e-05
9.52468407e-05 9.52468407e-05]
[9.12154233e-05 9.12154233e-05 9.12154233e-05 ... 9.12154233e-05
9.12154233e-05 9.12154233e-05]
[9.23888998e-05 9.23888998e-05 9.23888998e-05 ... 9.23888998e-05
9.23888998e-05 9.23888998e-05]
...
[9.21707665e-05 9.21707665e-05 9.21707665e-05 ... 9.21707665e-05
9.21707665e-05 9.21707665e-05]
[9.17963675e-05 9.17963675e-05 9.17963675e-05 ... 9.17963675e-05
9.17963675e-05 9.17963675e-05]
[8.97908506e-05 8.97908506e-05 8.97908506e-05 ... 8.97908506e-05
8.97908506e-05 8.97908506e-05]]
[[9.22576003e-05 9.22576003e-05 9.22576003e-05 ... 9.36309637e-05
9.36309637e-05 9.36309637e-05]
[9.03873698e-05 9.03873698e-05 9.03873698e-05 ... 9.00975483e-05
9.00975483e-05 9.00975483e-05]
[8.98063145e-05 8.98063145e-05 8.98063145e-05 ... 9.98612139e-05
9.98612139e-05 9.98612139e-05]
...
[8.75216760e-05 8.75216760e-05 8.75216760e-05 ... 8.70995732e-05
8.70995732e-05 8.70995732e-05]
[9.43218047e-05 9.43218047e-05 9.43218047e-05 ... 9.43218047e-05
9.43218047e-05 9.43218047e-05]
[9.07522398e-05 9.07522398e-05 9.07522398e-05 ... 9.07522398e-05
9.07522398e-05 9.07522398e-05]]
[[8.90395026e-05 8.90395026e-05 8.90395026e-05 ... 8.90780029e-05
8.90780029e-05 8.90780029e-05]
[9.13763498e-05 9.13763498e-05 9.13763498e-05 ... 9.25795293e-05
9.25795293e-05 9.25795293e-05]
[8.81328146e-05 8.81328146e-05 8.81328146e-05 ... 1.11208607e-04
1.11208607e-04 1.11208607e-04]
...
[9.35448308e-05 9.35448308e-05 9.35448308e-05 ... 9.25673329e-05
9.25673329e-05 9.25673329e-05]
[9.34936602e-05 9.34936602e-05 9.34936602e-05 ... 9.34936602e-05
9.34936602e-05 9.34936602e-05]
[9.25817130e-05 9.25817130e-05 9.25817130e-05 ... 9.17516729e-05
9.17516729e-05 9.17516729e-05]]
...
[[9.12143559e-05 9.12143559e-05 9.12143559e-05 ... 9.34941116e-05
9.34941116e-05 9.34941116e-05]
[9.08949654e-05 9.08949654e-05 9.08949654e-05 ... 9.36052083e-05
9.36052083e-05 9.36052083e-05]
[9.12819229e-05 9.12819229e-05 9.12819229e-05 ... 1.01782794e-04
1.01782794e-04 1.01782794e-04]
...
[9.35687016e-05 9.35687016e-05 9.35687016e-05 ... 8.93653526e-05
8.93653526e-05 8.93653526e-05]
[9.03563247e-05 9.03563247e-05 9.03563247e-05 ... 9.19574670e-05
9.19574670e-05 9.19574670e-05]
[9.07462310e-05 9.07462310e-05 9.07462310e-05 ... 1.36651830e-04
1.36651830e-04 1.36651830e-04]]
[[8.71620653e-05 8.71620653e-05 8.71620653e-05 ... 8.93968411e-05
8.93968411e-05 8.93968411e-05]
[9.15776336e-05 9.15776336e-05 9.15776336e-05 ... 9.21726746e-05
9.21726746e-05 9.21726746e-05]
[9.02941371e-05 9.02941371e-05 9.02941371e-05 ... 9.77740590e-05
9.77740590e-05 9.77740590e-05]
...
[9.41974715e-05 9.41974715e-05 9.41974715e-05 ... 9.33400837e-05
9.33400837e-05 9.33400837e-05]
[9.20223845e-05 9.20223845e-05 9.20223845e-05 ... 9.20223845e-05
9.20223845e-05 9.20223845e-05]
[9.07600498e-05 9.07600498e-05 9.07600498e-05 ... 9.16629035e-05
9.16629035e-05 9.16629035e-05]]
[[9.49552855e-05 9.49552855e-05 9.49552855e-05 ... 9.49552855e-05
9.49552855e-05 9.49552855e-05]
[8.94452015e-05 8.94452015e-05 8.94452015e-05 ... 8.94452015e-05
8.94452015e-05 8.94452015e-05]
[8.66647224e-05 8.66647224e-05 8.66647224e-05 ... 8.66647224e-05
8.66647224e-05 8.66647224e-05]
...
[9.30367866e-05 9.30367866e-05 9.30367866e-05 ... 9.30367866e-05
9.30367866e-05 9.30367866e-05]
[9.42973310e-05 9.42973310e-05 9.42973310e-05 ... 9.42973310e-05
9.42973310e-05 9.42973310e-05]
[9.55101224e-05 9.55101224e-05 9.55101224e-05 ... 9.55101224e-05
9.55101224e-05 9.55101224e-05]]]
There are total 48,400,000 data inside the np.array.
Actually, it is a 484 * 10 array under 1,000 different conditions.
I want to display a 484 * 10 array with 1,000 different colormap, but due to my short knowledge, it's not working atm.
my codes look like this;
import numpy as np
import matplotlib.pyplot as plt
data = np.load('C:/Users/**/***.npz', allow_pickle=True)
print(data.files)
print(data['weights'])
x = (data['weights'])
y = np.split(x, [4840]) # Here, i wanted to split data for each array
z = np.reshape(y, 4840*10) # Here, i wanted to reshape the array for colormap
cs = plt.imshow(z)
plt.colorbar()
print(z.shape)
plt.show()
Solution
Starting from your code, reshape your array and iterate over each of the 1000 2D arrays:
import numpy as np
import matplotlib.pyplot as plt
data = np.load('C:/Users/**/***.npz', allow_pickle=True)
print(data.files)
print(data['weights'])
x = data['weights']
x = x.reshape((4840, 10, 1000))
for i in range(x.shape[2]): # x.shape[2] == 1000
plt.imshow(x[:, i])
plt.show()
Answered By - Yakov Dan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.