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

Method squeeze

numpy/matrixlib/defmatrix.py:324–373  ·  view source on GitHub ↗

Return a possibly reshaped matrix. Refer to `numpy.squeeze` for more documentation. Parameters ---------- axis : None or int or tuple of ints, optional Selects a subset of the axes of length one in the shape. If an axis is selected w

(self, axis=None)

Source from the content-addressed store, hash-verified

322
323 # To update docstring from array to matrix...
324 def squeeze(self, axis=None):
325 """
326 Return a possibly reshaped matrix.
327
328 Refer to `numpy.squeeze` for more documentation.
329
330 Parameters
331 ----------
332 axis : None or int or tuple of ints, optional
333 Selects a subset of the axes of length one in the shape.
334 If an axis is selected with shape entry greater than one,
335 an error is raised.
336
337 Returns
338 -------
339 squeezed : matrix
340 The matrix, but as a (1, N) matrix if it had shape (N, 1).
341
342 See Also
343 --------
344 numpy.squeeze : related function
345
346 Notes
347 -----
348 If `m` has a single column then that column is returned
349 as the single row of a matrix. Otherwise `m` is returned.
350 The returned matrix is always either `m` itself or a view into `m`.
351 Supplying an axis keyword argument will not affect the returned matrix
352 but it may cause an error to be raised.
353
354 Examples
355 --------
356 >>> c = np.matrix([[1], [2]])
357 >>> c
358 matrix([[1],
359 [2]])
360 >>> c.squeeze()
361 matrix([[1, 2]])
362 >>> r = c.T
363 >>> r
364 matrix([[1, 2]])
365 >>> r.squeeze()
366 matrix([[1, 2]])
367 >>> m = np.matrix([[1, 2], [3, 4]])
368 >>> m.squeeze()
369 matrix([[1, 2],
370 [3, 4]])
371
372 """
373 return N.ndarray.squeeze(self, axis=axis)
374
375
376 # To update docstring from array to matrix...

Callers 15

contentsMethod · 0.45
_ensure_ndmin_ndarrayFunction · 0.45
_get_linear_rampsFunction · 0.45
covFunction · 0.45
nanvarFunction · 0.45
sum_to_0dMethod · 0.45
test_functionalityMethod · 0.45
test_basicMethod · 0.45
test_simpleMethod · 0.45
lstsqFunction · 0.45
test_keepdimsMethod · 0.45

Calls

no outgoing calls

Tested by 7

sum_to_0dMethod · 0.36
test_functionalityMethod · 0.36
test_basicMethod · 0.36
test_simpleMethod · 0.36
test_keepdimsMethod · 0.36
test_squeezeMethod · 0.36
test_view_to_typeMethod · 0.36