
上QQ阅读APP看书,第一时间看更新
How to do it...
Perform the following steps:
- Import all necessary modules:
import cv2, numpy as np
- Create a matrix with random values initialization and print its attributes:
mat = np.random.rand(100, 100).astype(np.float32)
print('Shape:', mat.shape)
print('Data type:', mat.dtype)
- Save our random matrix to the file with the np.savetxt function:
np.savetxt('mat.csv', mat)
- Now, load it from the file we've just written and print its shape and type:
mat = np.loadtxt('mat.csv').astype(np.float32)
print('Shape:', mat.shape)
print('Data type:', mat.dtype)