code: def test_to_numpy(self):
      try:
          import numpy as np
      except ImportError:
          pytest.skip("numpy not available")
  
      xy = pyvips.Image.xyz(4, 5)
  
      # using __array__ interface:
  
      from pyvips.vimage import TYPESTR_TO_FORMAT
  
      for typestr, format in TYPESTR_TO_FORMAT.items():
          this_xy = xy.cast(format)
          if typestr == "|b1":
              yx = np.asarray(this_xy, dtype=typestr)
          else:
              yx = np.array(this_xy)
  
          assert yx.dtype == np.dtype(typestr)
          assert yx.shape == (5, 4, 2)
          assert all(
              yx.max(axis=(0, 1)) == np.array([3, 4], dtype=typestr)
          )
  
      x, y = xy
      x_iy = pyvips.Image.complexform(x, y)
      x_iy_dp = x_iy.cast("dpcomplex")
  
      a = np.array(x_iy)
      assert a.shape == (5, 4)
      assert a.dtype == np.dtype("complex64")
      assert a[4, 3].item() == 3 + 4j
  
      a = np.array(x_iy_dp)
      assert a.shape == (5, 4)
      assert a.dtype == np.dtype("complex128")
      assert a[4, 3].item() == 3 + 4j
  
      xyxyxy = xy.bandjoin([xy, xy])
      a = np.array(xyxyxy)
      assert a.shape == (5, 4, 6)
  
      # axes collapsing:
      xyxyxy_col = xyxyxy.crop(3, 0, 1, 5)
      assert xyxyxy_col.width == 1
      assert xyxyxy_col.height == 5
      a = np.array(xyxyxy_col)
      assert a.shape == (5, 1, 6)
  
      xyxyxy_row = xyxyxy.crop(0, 4, 4, 1)
      assert xyxyxy_row.width == 4
      assert xyxyxy_row.height == 1
      a = np.array(xyxyxy_row)
      assert a.shape == (1, 4, 6)
  
      xyxyxy_px = xyxyxy.crop(3, 4, 1, 1)
      assert xyxyxy_px.width == 1
      assert xyxyxy_px.height == 1
      a = np.array(xyxyxy_px)
      assert a.shape == (1, 1, 6)
  
      a = np.array(xyxyxy_px[0])
      assert a.ndim == 0
  
      # automatic conversion to array on ufunc application:
  
      d = np.diff(xy.cast("short"), axis=1)
      assert (d[..., 0] == 1).all()
      assert (d[..., 1] == 0).all()
  
      # tests of .numpy() method:
  
      a = pyvips.Image.xyz(256, 1)[0].numpy().squeeze()
  
      assert all(a == np.arange(256))
  
file_path: pyvips/tests/test_image.py
imports: import pyvips
  import pytest
  from helpers import JPEG_FILE
label_desc: Use image node_id 6 for calling the TestImage obj's underlying member method code with example usage: obj.test_to_numpy() without return types