首页 > 解决方案 > “无”出现在矩阵之前

问题描述

我编写了一个程序,它生成矩阵 7x7,然后对其进行旋转和转置。在输出中我看到这个“无”

import time
import numpy as np
matsize = np.array([7,7])
matrix = np.random.randint(1000,size=(matsize))
print('\nSwource matrix:\n', matrix, '\n')

rotmatr = np.rot90(matrix, k=-1)
print('Rotation to 90 degrees...\n')
print(time.sleep(2), rotmatr, '\n')

transpos = np.transpose(rotmatr)
print('Transposing...\n')
print(time.sleep(2), transpos)

代码如何工作的示例

Swource matrix:
 [[909 859 984 490 773 696 576]
 [780 645 632 233 109 181  18]
 [ 81 890 328 746 930  45 999]
 [944 992 556 436 545 210 814]
 [192 827 820 321  45 959 940]
 [921 529 276 996 141 132 183]
 [235 842 287 169  71 857  70]] 

Rotation to 90 degrees...

None [[235 921 192 944  81 780 909]
 [842 529 827 992 890 645 859]
 [287 276 820 556 328 632 984]
 [169 996 321 436 746 233 490]
 [ 71 141  45 545 930 109 773]
 [857 132 959 210  45 181 696]
 [ 70 183 940 814 999  18 576]] 

Transposing...

None [[235 842 287 169  71 857  70]
 [921 529 276 996 141 132 183]
 [192 827 820 321  45 959 940]
 [944 992 556 436 545 210 814]
 [ 81 890 328 746 930  45 999]
 [780 645 632 233 109 181  18]
 [909 859 984 490 773 696 576]]

Process finished with exit code 0

这个NONE是什么以及如何删除它???

标签: pythonmatrix

解决方案


如果你time.sleep(2)从你的print陈述中删除,那将删除None


推荐阅读