MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / reduce_to_2d

Function reduce_to_2d

tensorboard/plugins/text/text_plugin.py:128–152  ·  view source on GitHub ↗

Given a np.npdarray with nDims > 2, reduce it to 2d. It does this by selecting the zeroth coordinate for every dimension greater than two. Args: arr: a numpy ndarray of dimension at least 2. Returns: A two-dimensional subarray from the input array. Raises: V

(arr)

Source from the content-addressed store, hash-verified

126
127
128def reduce_to_2d(arr):
129 """Given a np.npdarray with nDims > 2, reduce it to 2d.
130
131 It does this by selecting the zeroth coordinate for every dimension greater
132 than two.
133
134 Args:
135 arr: a numpy ndarray of dimension at least 2.
136
137 Returns:
138 A two-dimensional subarray from the input array.
139
140 Raises:
141 ValueError: If the argument is not a numpy ndarray, or the dimensionality
142 is too low.
143 """
144 if not isinstance(arr, np.ndarray):
145 raise ValueError("reduce_to_2d requires a numpy.ndarray")
146
147 ndims = len(arr.shape)
148 if ndims < 2:
149 raise ValueError("reduce_to_2d requires an array of dimensionality >=2")
150 # slice(None) is equivalent to `:`, so we take arr[0,0,...0,:,:]
151 slices = ([0] * (ndims - 2)) + [slice(None), slice(None)]
152 return arr[tuple(slices)]
153
154
155def text_array_to_html(text_arr, enable_markdown):

Callers 1

text_array_to_htmlFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…