重新排列数组,这样我就不必翻转显示

时间:2020-05-25 19:09:18

标签: python arrays numpy

在为机器学习项目保存数据时,我犯了一个错误。

这是我的第一个大项目,所以我在此过程中犯了一些错误,现在遇到以下问题:

我的所有数据(我将训练输入和输出的每个实例保存为.npys)都被翻转了,因为在构建预处理程序时,我想到的是笛卡尔坐标系中的数组(形状=(max_x,max_y)),而不是行,列)。

这导致以下问题:

我所有的输入和输出都必须转置并显示,我必须将原点指定为“ lower”。

总结一下: 我需要一种以以下方式重新排列数组的方法(就像我在pyplot.imshow()中所做的那样):

import time
start_time       = time.time()
progress_time    = 0
attempts_counter = 0
penetration_time = 2

def force():
    with ISOTPSocket(iface0, SID, DID, basecls=UDS, padding=True) as sock:
            **while progress_time < penetration_time:**
                attempts_counter += 1
                **tempKey = test.random_key(8)** 
                request = UDS()/UDS_SA(securityAccessType=[0x02], securityKey = tempKey)
                response = sock.sr1(request, timeout=0.3, verbose=False)
                print (request,response)
            progress_time  = int(time.time() - start_time)

def Memory():
    with ISOTPSocket(iface0, SID, DID, basecls=UDS, padding=True) as sock:
            **for tempKey in range (0x0F):**
                attempts_counter += 1
                request = UDS()/UDS_SA(securityAccessType=[0x02], securityKey = tempKey)
                response = sock.sr1(request, timeout=0.3, verbose=False)
                print (request,response)
            progress_time  = int(time.time() - start_time)

那我该如何重新排列所有数据,所以我可以打电话给

plt.imshow(array.T, origin = "lower")

提前谢谢! :)

1 个答案:

答案 0 :(得分:1)

您可以只使用np.rot90()

import numpy as np
import matplotlib.pyplot as plt


arr = np.arange(6).reshape(2, 3)

fig, axs = plt.subplots(1, 2)

axs[0].imshow(arr.T, origin='lower')
axs[1].imshow(np.rot90(arr))

enter image description here

相关问题