{"record":{"id":"62ce6b2662b665cc","repo":"TheAlgorithms/Python","slug":"wrong-input-data-s-shape-dataset-dataset-sha","errorCode":null,"errorMessage":"Wrong input data's shape... dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}","messagePattern":"Wrong input data's shape\\.\\.\\. dataset : (.+?), value_array : (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"machine_learning/similarity_search.py","lineNumber":113,"sourceCode":"        ...\n    TypeError: Input data have different datatype...\n    dataset : float32, value_array : int32\n    \"\"\"\n\n    if dataset.ndim != value_array.ndim:\n        msg = (\n            \"Wrong input data's dimensions... \"\n            f\"dataset : {dataset.ndim}, value_array : {value_array.ndim}\"\n        )\n        raise ValueError(msg)\n\n    try:\n        if dataset.shape[1] != value_array.shape[1]:\n            msg = (\n                \"Wrong input data's shape... \"\n                f\"dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}\"\n            )\n            raise ValueError(msg)\n    except IndexError:\n        if dataset.ndim != value_array.ndim:\n            raise TypeError(\"Wrong shape\")\n\n    if dataset.dtype != value_array.dtype:\n        msg = (\n            \"Input data have different datatype... \"\n            f\"dataset : {dataset.dtype}, value_array : {value_array.dtype}\"\n        )\n        raise TypeError(msg)\n\n    answer = []\n\n    for value in value_array:\n        dist = euclidean(value, dataset[0])\n        vector = dataset[0].tolist()\n\n        for dataset_value in dataset[1:]:","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/machine_learning/similarity_search.py#L95-L131","documentation":"Raised by similarity_search when dataset and value_array agree on dimension count but their feature (column) dimension shape[1] differs. Each query vector must have exactly as many coordinates as the dataset points so that pairwise Euclidean distances are defined.","triggerScenarios":"Calling similarity_search(dataset, value_array) where dataset.shape[1] != value_array.shape[1], e.g. dataset points of length 3 against query vectors of length 2. With equal ndim the IndexError guard is skipped and the explicit ValueError fires.","commonSituations":"Querying with vectors built from a different feature pipeline than the reference dataset, dropping a column during preprocessing of one side only, or loading datasets with an trailing index column on one array.","solutions":["Align feature counts: recompute query vectors from the same feature extraction used to build the dataset.","Drop or add the offending column explicitly (e.g. remove the ID column) so both shape[1] values match.","Assert equality of shapes before the call: dataset.shape[1] == value_array.shape[1]."],"exampleFix":"# before\nresult = similarity_search(dataset, queries)  # (100, 3) vs (10, 2)\n\n# after\nassert dataset.shape[1] == queries.shape[1]\nresult = similarity_search(dataset, queries)","handlingStrategy":"validation","validationCode":"assert dataset.shape[1] == value_array.shape[1], (\n    f\"feature mismatch: {dataset.shape[1]} vs {value_array.shape[1]}\"\n)\nresult = similarity_search(dataset, value_array)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build dataset and queries through the same feature-extraction function.","Store the expected feature count with the dataset and validate queries against it."],"tags":["numpy","input-validation","similarity-search"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}