[Python] Python Neural Network : TypeError: exceptions must derive from BaseException

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I want to use python to training my neural network case, but I recognize a problem.

    The console code looks like:

    [​IMG]

    The original code:

    @staticmethod
    def colSpec(nparray: 'np.ndarray', rangeStr:str=None,batchStart:str=None, batchEnd:str=None)->'np.ndarray':
    '''
    Specify certain column data by selecting some columns or batched rows of data. --- UPDATED (Dexter) 20181210

    Parameters
    ------------------------------

    nparray `np.ndarray<np.array<(int|float|str)>>` - Data table to be selected.

    rangeStr `str` - Index range string for selecting certain columns for the transformation.

    batchStart `int` - The starting index (inclusive) of the data rows.

    batchEnd `int` - The ending index (exclusive) of the data rows.

    Returns
    ------------------------------

    `np.ndarray<np.array<(int|float|str)>>` - Data table with requested selection range.
    '''
    # Convert to np array if it's not.
    if not isinstance(nparray, np.ndarray):
    if isinstance(nparray, list):
    try:
    nparray = np.array(nparray)
    except:
    raise ValueError("Data type not supported for colSpec. It should be an `np.ndarray` object.")
    else:
    raise ValueError("Data type not supported for colSpec. It should be an `np.ndarray` object.")

    # If no column specification requested, just return the orginal array with batchStart and batchEnd rows.
    if rangeStr is None:
    return nparray[batchStart:batchEnd]

    else:
    colCount = len(nparray[0])

    # Validate the index range range.
    if (not IndexRange.validate(colCount, rangeStr)):
    raise ValueError("Index range string is not valid.")

    # Different scenarios on the column selections:
    if ":" in rangeStr:
    # Split the ":" to find the range start and end.
    rangeInfo = [string.strip() for string in rangeStr.split(":")]

    # None should be specified for 2-valued tuples.
    if any([(ele == "None" or ele == "") for ele in rangeInfo]):
    # Determine the scenarios for which None is used.
    if rangeInfo[0] != "None" and len(rangeInfo[0]):
    return nparray[batchStart:batchEnd,int(rangeInfo[0]):]
    elif rangeInfo[1] != "None" and len(rangeInfo[1]):
    return nparray[batchStart:batchEnd,:int(rangeInfo[1])]
    else:
    return nparray[batchStart:batchEnd]
    else:
    raise nparray[batchStart:batchEnd,int(rangeInfo[0]):int(rangeInfo[1])]

    # Otherwise, it is specifying indexes explicitly.
    else:
    idxs = IndexRange.parse(colCount, rangeStr)
    return nparray[batchStart:batchEnd,idxs]


    I don't what's wrong about that, I even don't use exceptions code.

    Continue reading...

Compartilhe esta Página