def concatenate(*arrays,axis:0)
      axis = check_axis(axis)
      self_shape = shape
      self_shape.delete_at(axis)
      sum_size = shape[axis]
      arrays.map! do |a|
        case a
        when NArray
          # ok
        when Numeric
          a = self.class.new(1).store(a)
        when Array
          a = self.class.cast(a)
        else
          raise TypeError,"not Numo::NArray: #{a.inspect[0..48]}"
        end
        if a.ndim > ndim
          raise ShapeError,"dimension mismatch"
        end
        a_shape = a.shape
        sum_size += a_shape.delete_at(axis-ndim) || 1
        if self_shape != a_shape
          raise ShapeError,"shape mismatch"
        end
        a
      end
      self_shape.insert(axis,sum_size)
      result = self.class.zeros(*self_shape)
      lst = shape[axis]
      refs = [true] * ndim
      if lst > 0
        refs[axis] = 0...lst
        result[*refs] = self
      end
      arrays.each do |a|
        fst = lst
        lst = fst + (a.shape[axis-ndim] || 1)
        if lst > fst
          refs[axis] = fst...lst
          result[*refs] = a
        end
      end
      result
    end
def concatenate(*arrays,axis:0)
      axis = check_axis(axis)
      self_shape = shape
      self_shape.delete_at(axis)
      sum_size = shape[axis]
      arrays.map! do |a|
        case a
        when NArray
          # ok
        when Numeric
          a = self.class.new(1).store(a)
        when Array
          a = self.class.cast(a)
        else
          raise TypeError,"not Numo::NArray: #{a.inspect[0..48]}"
        end
        if a.ndim > ndim
          raise ShapeError,"dimension mismatch"
        end
        a_shape = a.shape
        sum_size += a_shape.delete_at(axis-ndim) || 1
        if self_shape != a_shape
          raise ShapeError,"shape mismatch"
        end
        a
      end
      self_shape.insert(axis,sum_size)
      result = self.class.zeros(*self_shape)
      lst = shape[axis]
      refs = [true] * ndim
      if lst > 0
        refs[axis] = 0...lst
        result[*refs] = self
      end
      arrays.each do |a|
        fst = lst
        lst = fst + (a.shape[axis-ndim] || 1)
        if lst > fst
          refs[axis] = fst...lst
          result[*refs] = a
        end
      end
      result
    end
class << self
 @example
   p a = Numo::DFloat[[1, 2], [3, 4]]
   # Numo::DFloat#shape=[2,2]
   # [[1, 2],
   #  [3, 4]]

   p b = Numo::DFloat[[5, 6]]
   # Numo::DFloat#shape=[1,2]
   # [[5, 6]]

   p a.concatenate(b,axis:0)
   # Numo::DFloat#shape=[3,2]
   # [[1, 2],
   #  [3, 4],
   #  [5, 6]]

   p a.concatenate(b.transpose, axis:1)
   # Numo::DFloat#shape=[2,3]
   # [[1, 2, 5],
   #  [3, 4, 6]]