MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / from_numpy

Method from_numpy

python/paddle/static/input.py:320–344  ·  view source on GitHub ↗

Generates a InputSpec based on the description of input np.ndarray. Args: tensor(Tensor): the source numpy ndarray to generate a InputSpec instance Returns: A InputSpec instance generated from Tensor. Examples: .. code-block:: p

(
        cls, ndarray: npt.NDArray[Any], name: str | None = None
    )

Source from the content-addressed store, hash-verified

318
319 @classmethod
320 def from_numpy(
321 cls, ndarray: npt.NDArray[Any], name: str | None = None
322 ) -> Self:
323 """
324 Generates a InputSpec based on the description of input np.ndarray.
325
326 Args:
327 tensor(Tensor): the source numpy ndarray to generate a InputSpec instance
328
329 Returns:
330 A InputSpec instance generated from Tensor.
331
332 Examples:
333 .. code-block:: pycon
334
335 >>> import numpy as np
336 >>> from paddle.static import InputSpec
337
338 >>> x = np.ones([2, 2], np.float32)
339 >>> x_spec = InputSpec.from_numpy(x, name='x')
340 >>> print(x_spec)
341 InputSpec(shape=(2, 2), dtype=paddle.float32, name=x, stop_gradient=False)
342
343 """
344 return cls(ndarray.shape, ndarray.dtype, name)
345
346 def batch(self, batch_size: int | Size1) -> Self:
347 """

Callers 15

_infer_item_specMethod · 0.45
test_from_numpyMethod · 0.45
test_baseMethod · 0.45
apply_testMethod · 0.45
apply_testMethod · 0.45
test_basicMethod · 0.45
apply_testMethod · 0.45
test_modelMethod · 0.45
test_modelMethod · 0.45
apply_testMethod · 0.45

Calls

no outgoing calls

Tested by 15

test_from_numpyMethod · 0.36
test_baseMethod · 0.36
apply_testMethod · 0.36
apply_testMethod · 0.36
test_basicMethod · 0.36
apply_testMethod · 0.36
test_modelMethod · 0.36
test_modelMethod · 0.36
apply_testMethod · 0.36
apply_testMethod · 0.36