# TypeError: Cannot convert value of type 'numpy.ndarray' to TensorFlow DType 'int32'

- **ID:** `tensorflow/type-error-tensorflow-dtype-mismatch`
- **Domain:** tensorflow
- **Category:** type_error
- **Error Code:** `TCD`
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

Passing a NumPy array where a scalar or tensor of a specific dtype is expected, often in tf.constant or model input.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| tensorflow 2.11.0 | active | — | — |
| numpy 1.24.0 | active | — | — |

## Workarounds

1. **Ensure the input is a scalar or reshape it appropriately:
import numpy as np
import tensorflow as tf
# Instead of passing array, pass scalar
val = np.array([5])  # This may fail
# Correct: pass scalar or use tf.constant with proper shape
scalar_val = int(val[0])
tf_constant = tf.constant(scalar_val, dtype=tf.int32)** (85% success)
   ```
   Ensure the input is a scalar or reshape it appropriately:
import numpy as np
import tensorflow as tf
# Instead of passing array, pass scalar
val = np.array([5])  # This may fail
# Correct: pass scalar or use tf.constant with proper shape
scalar_val = int(val[0])
tf_constant = tf.constant(scalar_val, dtype=tf.int32)
   ```
2. **Use tf.convert_to_tensor to explicitly convert the array before use:
tensor = tf.convert_to_tensor(np.array([1,2,3]), dtype=tf.int32)
# Then use tensor in place of the original array** (80% success)
   ```
   Use tf.convert_to_tensor to explicitly convert the array before use:
tensor = tf.convert_to_tensor(np.array([1,2,3]), dtype=tf.int32)
# Then use tensor in place of the original array
   ```

## Dead Ends

- **** — tf.cast preserves shape; if shape is wrong, error persists. (85% fail)
- **** — tf.constant expects a scalar or list, not a multi-dimensional array in this context. (90% fail)
