MCPcopy Create free account
hub / github.com/numpy/numpy / SubArrayFormat

Class SubArrayFormat

numpy/core/arrayprint.py:1341–1364  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1339
1340
1341class SubArrayFormat:
1342 def __init__(self, format_function, **options):
1343 self.format_function = format_function
1344 self.threshold = options['threshold']
1345 self.edge_items = options['edgeitems']
1346
1347 def __call__(self, a):
1348 self.summary_insert = "..." if a.size > self.threshold else ""
1349 return self.format_array(a)
1350
1351 def format_array(self, a):
1352 if np.ndim(a) == 0:
1353 return self.format_function(a)
1354
1355 if self.summary_insert and a.shape[0] > 2*self.edge_items:
1356 formatted = (
1357 [self.format_array(a_) for a_ in a[:self.edge_items]]
1358 + [self.summary_insert]
1359 + [self.format_array(a_) for a_ in a[-self.edge_items:]]
1360 )
1361 else:
1362 formatted = [self.format_array(a_) for a_ in a]
1363
1364 return "[" + ", ".join(formatted) + "]"
1365
1366
1367class StructuredVoidFormat:

Callers 1

from_dataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected