OpenCV 3 Computer Vision with Python Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

Perform the following steps:

  1. Import all necessary modules:
import cv2, numpy as np
  1. 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)
  1. Save our random matrix to the file with the np.savetxt function:
np.savetxt('mat.csv', mat)
  1. 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)