Last active
November 10, 2016 21:52
-
-
Save nticaric/135475a00c0a5c9690bdf5e38d42783c to your computer and use it in GitHub Desktop.
A function that returns an array containing MNIST labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function loadMNISTLabels($filename) | |
{ | |
$fp = fopen($filename, 'rb'); | |
$array = unpack("N2", fread($fp, 8)); | |
$magic = $array[1]; | |
if($magic != 2049) { | |
throw new Exception("Bad magic number in $filename", 1); | |
} | |
$numLabels = $array[2]; | |
$stream = stream_get_contents($fp); | |
$labels = unpack("C$numLabels", $stream); | |
fclose($fp); | |
return array_values($labels); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment