code: def to_matrix(np_array):
      
      if len(np_array.shape) == 2:
          return Matrices.dense(np_array.shape[0],
                                np_array.shape[1],
                                np_array.ravel())
      else:
          raise Exception("An MLLib Matrix can only be created from a two-dimensional " +
                          "numpy array, got {}".format(len(np_array.shape)))
docs: Convert numpy array to MLlib Matrix