code: def test_from_numpy(self):
      try:
          import numpy as np
      except ImportError:
          pytest.skip("numpy not available")
  
      a = np.indices((5, 4)).transpose(1, 2, 0)  # (5, 4, 2)
  
      with pytest.raises(ValueError):
          # no way in for int64
          yx = pyvips.Image.new_from_array(a)
  
      from pyvips.vimage import TYPESTR_TO_FORMAT
  
      for typestr, format in TYPESTR_TO_FORMAT.items():
          if typestr == "|b1":
              continue
          a = np.indices((5, 4), dtype=typestr).transpose(1, 2, 0)
          yx = pyvips.Image.new_from_array(a)
          assert yx.format == format
  
      a = np.zeros((2, 2, 2, 2))
  
      with pytest.raises(ValueError):
          # too many dimensions
          im = pyvips.Image.new_from_array(a)
  
      a = np.ones((2, 2, 2), dtype=bool)
      im = pyvips.Image.new_from_array(a)
      assert im.max() == 255
  
      a = np.ones((2, 2, 2), dtype="S8")
      with pytest.raises(ValueError):
          # no way in for strings
          im = pyvips.Image.new_from_array(a)
  
      # test handling of strided data
      a = np.ones((1000, 1000, 3), dtype="uint8")[::10, ::10]
      im = pyvips.Image.new_from_array(a)
      assert im.width == 100
      assert im.height == 100
      assert im.bands == 3
  
      class FakeArray(object):
          @property
          def __array_interface__(self):
              return {
                  "shape": (1, 1, 1),
                  "typestr": "|u1",
                  "version": 3,
              }
  
      with pytest.raises(TypeError):
          # Handle evil objects that don't behave like ndarrays
          im = pyvips.Image.new_from_array(FakeArray())
  
file_path: pyvips/tests/test_image.py
imports: import pyvips
  import pytest
  from helpers import JPEG_FILE
label_desc: Use image node_id 9 for calling the TestImage obj's underlying member method code with example usage: obj.test_from_numpy() and returns: dict