TheAlgorithms/Python · error · ValueError
Wrong input data's shape... dataset : {dataset.shape[1]}, va
Error message
Wrong input data's shape... dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]} What it means
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.
Source
Thrown at machine_learning/similarity_search.py:113
...
TypeError: Input data have different datatype...
dataset : float32, value_array : int32
"""
if dataset.ndim != value_array.ndim:
msg = (
"Wrong input data's dimensions... "
f"dataset : {dataset.ndim}, value_array : {value_array.ndim}"
)
raise ValueError(msg)
try:
if dataset.shape[1] != value_array.shape[1]:
msg = (
"Wrong input data's shape... "
f"dataset : {dataset.shape[1]}, value_array : {value_array.shape[1]}"
)
raise ValueError(msg)
except IndexError:
if dataset.ndim != value_array.ndim:
raise TypeError("Wrong shape")
if dataset.dtype != value_array.dtype:
msg = (
"Input data have different datatype... "
f"dataset : {dataset.dtype}, value_array : {value_array.dtype}"
)
raise TypeError(msg)
answer = []
for value in value_array:
dist = euclidean(value, dataset[0])
vector = dataset[0].tolist()
for dataset_value in dataset[1:]:View on GitHub (pinned to f5988cc097)
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].
Example fix
# before result = similarity_search(dataset, queries) # (100, 3) vs (10, 2) # after assert dataset.shape[1] == queries.shape[1] result = similarity_search(dataset, queries)
Defensive patterns
Strategy: validation
Validate before calling
assert dataset.shape[1] == value_array.shape[1], (
f"feature mismatch: {dataset.shape[1]} vs {value_array.shape[1]}"
)
result = similarity_search(dataset, value_array) Prevention
- Build dataset and queries through the same feature-extraction function.
- Store the expected feature count with the dataset and validate queries against it.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Wrong input data's dimensions... dataset : {dataset.ndim}, v
- Input data have different datatype... dataset : {dataset.dty
- Test samples' feature length does not equal to that of train
- Expected a_coeffs to have {self.order + 1} elements for {sel
- Expected b_coeffs to have {self.order + 1} elements for {sel
AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14).
Data as JSON: /api/errors/62ce6b2662b665cc.
Report an issue: GitHub.