import numpy as np
def noZeros(a):
arr = np.array(a)
rows = arr[ ~np.all(arr == 0, axis = 1)]
colsTrue = ~np.all(rows == 0, axis = 0)
return rows[:, colsTrue == True]
a = [
[0,4,0,1,0],
[0,0,2,3,0],
[0,0,3,1,0],
[0,0,0,0,0],
]
noZeros(a)
array([[4, 0, 1],
[0, 2, 3],
[0, 3, 1]])
© Вася Пупкин <?php echo date('Y'); ?>
v
. [offset] [type] [value] [description]
0000 32 bit integer 0x00000803(2051) magic number
0004 32 bit integer 60000 number of images
0008 32 bit integer 28 number of rows
0012 32 bit integer 28 number of columns
0016 unsigned byte ?? pixel
0017 unsigned byte ?? pixel
........
xxxx unsigned byte ?? pixel
Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).
$fh = fopen('train-images-idx3-ubyte', 'rb');
fseek( $fh, 16);
$byteString = fread($fh, 784);
$arr = unpack( 'C*', $byteString);
$arr[28] // яркость первого пикселя во второй строке
написать и подключить скриптGoogle Apps Script хорошо документрирован. У вас всё получится.
function nearest(arr, total) {
var len = arr.length
, i
, bit
, sum
, n = Math.pow(2, len)
, currDist
, index = undefined
, dist = undefined
, result = []
;
for( i = 1; i < n; i++) {
sum = 0;
for( bit = 0; bit < len; bit++) {
if( i & (1 << bit)) sum += arr[bit];
}
currDist = Math.abs(total - sum);
if( typeof dist === 'undefined' || dist > currDist) {
index = i;
dist = currDist;
if( dist === 0) break;
}
}
for(bit = 0; bit < len; bit++) {
if( index & (1 << bit)) result.push(arr[bit]);
}
return result;
}
nearest([1,3,4,6,8], 12) // [1,3,8]
nearest([1,2,4,6,8], 12) // [2,4,6]
nearest([7,9,13,19,28], 12) // [13] dist = 1
nearest([7,9,13,19,28], 28) // [9,19] не [28] т.к. останавливается на первом найденном варианте