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)

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.