    def _from_sample(self, sample: ext.NpNDArray | t.Sequence[t.Any]) -> ext.NpNDArray:
        """
        Create a :class:`~bentoml._internal.io_descriptors.numpy.NumpyNdarray` IO Descriptor from given inputs.

        Args:
            sample: Given sample ``np.ndarray`` data. It also accepts a sequence-like data type that
                    can be converted to ``np.ndarray``.
            enforce_dtype: Enforce a certain data type. :code:`dtype` must be specified at function
                           signature. If you don't want to enforce a specific dtype then change
                           :code:`enforce_dtype=False`.
            enforce_shape: Enforce a certain shape. :code:`shape` must be specified at function
                           signature. If you don't want to enforce a specific shape then change
                           :code:`enforce_shape=False`.

        Returns:
            :class:`~bentoml._internal.io_descriptors.numpy.NumpyNdarray`: IODescriptor from given users inputs.

        Example:

        .. code-block:: python
           :caption: `service.py`

           from __future__ import annotations

           from typing import TYPE_CHECKING, Any

           import bentoml
           from bentoml.io import NumpyNdarray

           import numpy as np

           if TYPE_CHECKING:
               from numpy.typing import NDArray

           input_spec = NumpyNdarray.from_sample(np.array([[1,2,3]]))

           @svc.api(input=input_spec, output=NumpyNdarray())
           async def predict(input: NDArray[np.int16]) -> NDArray[Any]:
               return await runner.async_run(input)

        Raises:
            :class:`BadInput`: If given sample is a type ``numpy.generic``. This exception
                                       will also be raised if we failed to create a ``np.ndarray``
                                       from given sample.
        """
        if isinstance(sample, np.generic):
            raise BadInput(
                "'NumpyNdarray.from_sample()' expects a 'numpy.array', not 'numpy.generic'."
            ) from None
        try:
            if not isinstance(sample, np.ndarray):
                sample = np.array(sample)
        except ValueError:
            raise BadInput(f"Given sample ({sample}) is not a numpy ND-array") from None
        if self._dtype is None:
            self._dtype = sample.dtype
        if self._shape is None:
            self._shape = sample.shape
        return sample
Create a :class:`~bentoml._internal.io_descriptors.numpy.NumpyNdarray` IO Descriptor from given inputs.

Args:
sample: Given sample ``np.ndarray`` data. It also accepts a sequence-like data type that
can be converted to ``np.ndarray``.
enforce_dtype: Enforce a certain data type. :code:`dtype` must be specified at function
signature. If you don't want to enforce a specific dtype then change
:code:`enforce_dtype=False`.
enforce_shape: Enforce a certain shape. :code:`shape` must be specified at function
signature. If you don't want to enforce a specific shape then change
:code:`enforce_shape=False`.

Returns:
:class:`~bentoml._internal.io_descriptors.numpy.NumpyNdarray`: IODescriptor from given users inputs.

Example:

.. code-block:: python
:caption: `service.py`

from __future__ import annotations

from typing import TYPE_CHECKING, Any

import bentoml
from bentoml.io import NumpyNdarray

import numpy as np

if TYPE_CHECKING:
from numpy.typing import NDArray

input_spec = NumpyNdarray.from_sample(np.array([[1,2,3]]))

@svc.api(input=input_spec, output=NumpyNdarray())
async def predict(input: NDArray[np.int16]) -> NDArray[Any]:
return await runner.async_run(input)

Raises:
:class:`BadInput`: If given sample is a type ``numpy.generic``. This exception
will also be raised if we failed to create a ``np.ndarray``
from given sample.
src/bentoml/_internal/io_descriptors/numpy.py