Implementation:Microsoft Onnxruntime Numpy Input Construction
Appearance
Metadata
| Field | Value |
|---|---|
| Implementation Name | Numpy_Input_Construction |
| Repository | Microsoft_Onnxruntime |
| Source Repository | https://github.com/microsoft/onnxruntime |
| Type | External Tool Doc |
| External Tool | numpy |
| Language | Python |
| Domain | ML_Inference, Model_Optimization |
| Last Updated | 2026-02-10 |
| Workflow | Python_Inference_Pipeline |
| Pair | 4 of 6 |
Overview
External tool documentation for constructing properly typed and shaped numpy arrays as input data for ONNX Runtime inference. This implementation relies on the numpy library for array creation and type casting.
API Signature
numpy.random.random(shape).astype(numpy.float32)
Or for user-supplied data:
numpy.array(data).astype(numpy.float32)
Import
import numpy
Code Reference
| Reference | Location |
|---|---|
| Usage example | docs/python/examples/plot_load_and_predict.py:L52-53 |
I/O Contract
Inputs
| Parameter | Type | Required | Description |
|---|---|---|---|
| Model input metadata | Names, shapes, types from session.get_inputs() |
Yes | Used to determine the correct array shape, dtype, and dictionary key. |
| Raw data | Any array-like | Yes | The actual data to be fed into the model (random, test data, or production data). |
Outputs
| Output | Type | Description |
|---|---|---|
| input_feed | dict[str, numpy.ndarray] |
Dictionary mapping input tensor names to correctly-typed numpy arrays. |
Usage Example
import numpy
# Generate random test input matching model shape
x = numpy.random.random((3, 4, 5)).astype(numpy.float32)
input_feed = {input_name: x}
From the source example at docs/python/examples/plot_load_and_predict.py:L52-53:
x = numpy.random.random((3, 4, 5))
x = x.astype(numpy.float32)
Common Type Conversions
# Float32 input (most common)
x = numpy.array(data).astype(numpy.float32)
# Int64 input (common for token IDs)
x = numpy.array(token_ids).astype(numpy.int64)
# Constructing multi-input feed
input_feed = {
sess.get_inputs()[0].name: input_array_1,
sess.get_inputs()[1].name: input_array_2,
}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment