def shape(matrix): if not F.is_sequence(matrix): return None len1 = len(matrix) if not (len1 > 0 and F.is_sequence(matrix[0])): return None len2 = len(matrix[0]) return [len1, len2]
def shape(matrix): if not F.is_sequence(matrix): return None shapes = [] acc_matrix = matrix while True: matrix_length = len(acc_matrix) shapes.append(matrix_length) if not F.is_sequence(acc_matrix[0]): return shapes acc_matrix = acc_matrix[0]
def test_is_sequence(self): self.assertEqual(F.is_sequence(_list), True) self.assertEqual(F.is_sequence(_tuple), True) self.assertEqual(F.is_sequence(_str), True) self.assertEqual(F.is_sequence(_dict), False) self.assertEqual(F.is_sequence(_class), False)
def sum(arg): if not F.is_sequence(arg): return None return F.reduce(arg, lambda a, b: a+b, 0)