Leave n samples and labels on this dataset and return the rest in a new
dataset.

@param int $n
@throws \InvalidArgumentException
@return self
321295
public function leave(int $n = 1) : self
    {
        if ($n < 0) {
            throw new InvalidArgumentException('Cannot leave less than 0 samples.');
        }

        return $this->splice($n, $this->numRows());
    }
520801
function drop ($n = 1)
  {
    $this->pack ();
    $this->data = array_slice ($this->data, 0, -$n);
    return $this;
  }
270484
public function setNumChildrenMethod($method)
    {
        // Check method is valid
        if (!$this->rootNode->hasMethod($method)) {
            throw new InvalidArgumentException(sprintf(
                "Can't find the method '%s' on class '%s' for counting tree children",
                $method,
                get_class($this->rootNode)
            ));
        }
        $this->numChildrenMethod = $method;
        return $this;
    }
19329
public static function gaussian(int $n) : self
    {
        if ($n < 1) {
            throw new InvalidArgumentException('The number of elements'
                . " must be greater than 0, $n given.");
        }

        $a = [];

        for ($i = 0; $i < $n; $i += 2) {
            $r1 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            $r2 = rand(0, PHP_INT_MAX) / PHP_INT_MAX;
            
            $r = sqrt(-2. * log($r1));

            $a[] = $r * sin($r2 * self::TWO_PI);
            $a[] = $r * cos($r2 * self::TWO_PI);
        }

        if (count($a) > $n) {
            $a = array_slice($a, 0, $n);
        }

        return static::quick($a);
    }
611640
public function allocateToTargets($n)
    {
        if (is_int($n)) {
            $n = (float)$n;
        }

        if (!is_float($n)) {
            throw new InvalidArgumentException('$n ' . \Yii::t('skeeks/money', 'must be an integer'));
        }

        $low = $this->newMoney(floatval($this->amount / $n));
        $high = $this->newMoney($low->getAmount() + 1);
        $remainder = $this->amount % $n;
        $result = array();

        for ($i = 0; $i < $remainder; $i++) {
            $result[] = $high;
        }

        for ($i = $remainder; $i < $n; $i++) {
            $result[] = $low;
        }

        return $result;
    }
602964
public function getNFirst($n)
    {
        $it = new \ArrayIterator();
        $j = 0;
        foreach ($this as $file) {
            if ($j == $n) {
                break;
            }
            $j++;
            $it->append($file);
        }

        $finder = new static();
        $finder->append($it);

        return $finder;
    }
1215670
public function toInstance($instance): self
    {
        if (!($instance instanceof $this->type)) {
            throw new \InvalidArgumentException(
                    'Instance of ' . $this->type . ' expectected, '
                    . get_class($instance) . ' given.'
            );
        }

        $this->instance = $instance;
        return $this;
    }
726329
public function tail(int $n = 10) : self
    {
        return self::quick(array_slice($this->samples, -$n));
    }
534246
public function setLabelPosition($labelPosition)
    {
        $labelPosition = strtolower($labelPosition);
        if (!in_array($labelPosition, array(self::LABEL_APPEND, self::LABEL_PREPEND))) {
            throw new Exception\InvalidArgumentException(sprintf(
                '%s expects either %s::LABEL_APPEND or %s::LABEL_PREPEND; received "%s"',
                __METHOD__,
                __CLASS__,
                __CLASS__,
                (string) $labelPosition
            ));
        }
        $this->labelPosition = $labelPosition;

        return $this;
    }
741987
public function create($dataset)
    {
        // Event
        $this->triggerEvent(
            'onBefore' . ucfirst(__FUNCTION__),
            [
                'dataset' => &$dataset,
            ]
        );

        if (!($dataset instanceof \Traversable) && !is_array($dataset)) {
            throw new \InvalidArgumentException('DataSet object should be instance of a Traversable');
        }

        $result = $this->doCreate($dataset);

        // Event
        $this->triggerEvent(
            'onAfter' . ucfirst(__FUNCTION__),
            [
                'result' => &$result,
            ]
        );

        return $result;
    }
43754
public function generate(int $n) : Dataset
    {
        $t = Vector::rand($n)->multiply(2)->add(1)
            ->multiply(1.5 * M_PI);

        $x = $t->multiply($t->cos());
        $y = Vector::rand($n)->multiply($this->depth);
        $z = $t->multiply($t->sin());

        $noise = Matrix::gaussian($n, 3)
            ->multiply($this->noise);
            
        $samples = Matrix::stack([$x, $y, $z])
            ->transpose()
            ->add($noise)
            ->multiply($this->scale)
            ->add($this->center)
            ->asArray();

        $labels = $t->asArray();

        return Labeled::quick($samples, $labels);
    }
397376
public function topN(int $n): self
    {
        if (!$this->isSorted) {
            usort($this->list, [$this, 'compare']);
            $this->isSorted = true;
        }

        $topNList = new self();
        $topNList->insertFromArray(array_slice($this->list, -$n, $n));

        return $topNList;
    }
581872
public static function fill($value, int $n) : self
    {
        if (!is_int($value) and !is_float($value)) {
            throw new InvalidArgumentException('Fill value expects an'
                . ' integer or float, ' . gettype($value) . ' found.');
        }

        if ($n < 1) {
            throw new InvalidArgumentException('The number of elements'
                . " must be greater than 0, $n given.");
        }

        return static::quick(array_fill(0, $n, $value));
    }
1213660
public function skip(int $n): self
    {
        return new self(new Limit($this->getIterator(), $n), $this->type);
    }
1135920
public function batch(int $n = 50) : array
    {
        $batches = [];

        $samples = $this->samples;

        foreach (array_chunk($this->samples, $n) as $batch) {
            $batches[] = self::quick($batch);
        }

        return $batches;
    }
1127335
public function label(int $index)
    {
        if (!isset($this->labels[$index])) {
            throw new InvalidArgumentException("Row at offset $index"
                . ' does not exist.');
        }

        return $this->labels[$index];
    }
911584
public function filterByColumn(int $index, callable $fn) : self
    {
        $samples = $labels = [];

        foreach ($this->samples as $i => $sample) {
            if ($fn($sample[$index])) {
                $samples[] = $sample;
                $labels[] = $this->labels[$i];
            }
        }

        return self::quick($samples, $labels);
    }