def __new__(cls, input_array, row_axes=None, col_axes=None, axis_names=None): if not isinstance(input_array, cls.info_base): raise ValueError("Array to convert must be instance of " + str(cls.info_base)) obj = input_array.view(cls) if 'type' in obj.info: if axis_names is not None or \ row_axes is not None or \ col_axes is not None: warnings.warn("Initialization argument ignored. Requisite " "metadata for matrix already exists. " "Clear info dictionary if you want opposite " "behaviour.") if obj.info['type'] != 'mat': raise ValueError("Meta data present is incompatible.") helpers.check_axis_names(obj) helpers.check_rows_cols(obj) else: if row_axes is None and \ col_axes is None and \ (input_array.ndim == 2): row_axes = (0, ) col_axes = (1, ) else: helpers.check_rows_cols(input_array, row_axes, col_axes) helpers.set_type_axes(obj, 'mat', axis_names) obj.rows = row_axes obj.cols = col_axes return obj
def __new__(cls, input_array, row_axes=None, col_axes=None, axis_names=None): if not isinstance(input_array, cls.info_base): raise ValueError("Array to convert must be instance of " + str(cls.info_base)) obj = input_array.view(cls) if 'type' in obj.info: if axis_names is not None or \ row_axes is not None or \ col_axes is not None: warnings.warn("Initialization argument ignored. Requisite " "metadata for matrix already exists. " "Clear info dictionary if you want opposite " "behaviour.") if obj.info['type'] != 'mat': raise ValueError("Meta data present is incompatible.") helpers.check_axis_names(obj) helpers.check_rows_cols(obj) else: if row_axes is None and \ col_axes is None and \ (input_array.ndim == 2): row_axes = (0,) col_axes = (1,) else: helpers.check_rows_cols(input_array, row_axes, col_axes) helpers.set_type_axes(obj, 'mat', axis_names) obj.rows = row_axes obj.cols = col_axes return obj
def check_rows_cols(self): """Check that rows and cols are valid for the matrix. Raises an exception if the rows or columns are invalid. """ helpers.check_rows_cols(self)