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

Function resize

numpy/ma/core.py:7377–7438  ·  view source on GitHub ↗

Return a new masked array with the specified size and shape. This is the masked equivalent of the `numpy.resize` function. The new array is filled with repeated copies of `x` (in the order that the data are stored in memory). If `x` is masked, the new array will be masked, and

(x, new_shape)

Source from the content-addressed store, hash-verified

7375
7376
7377def resize(x, new_shape):
7378 """
7379 Return a new masked array with the specified size and shape.
7380
7381 This is the masked equivalent of the `numpy.resize` function. The new
7382 array is filled with repeated copies of `x` (in the order that the
7383 data are stored in memory). If `x` is masked, the new array will be
7384 masked, and the new mask will be a repetition of the old one.
7385
7386 See Also
7387 --------
7388 numpy.resize : Equivalent function in the top level NumPy module.
7389
7390 Examples
7391 --------
7392 >>> import numpy.ma as ma
7393 >>> a = ma.array([[1, 2] ,[3, 4]])
7394 >>> a[0, 1] = ma.masked
7395 >>> a
7396 masked_array(
7397 data=[[1, --],
7398 [3, 4]],
7399 mask=[[False, True],
7400 [False, False]],
7401 fill_value=999999)
7402 >>> np.resize(a, (3, 3))
7403 masked_array(
7404 data=[[1, 2, 3],
7405 [4, 1, 2],
7406 [3, 4, 1]],
7407 mask=False,
7408 fill_value=999999)
7409 >>> ma.resize(a, (3, 3))
7410 masked_array(
7411 data=[[1, --, 3],
7412 [4, 1, --],
7413 [3, 4, 1]],
7414 mask=[[False, True, False],
7415 [False, False, True],
7416 [False, False, False]],
7417 fill_value=999999)
7418
7419 A MaskedArray is always returned, regardless of the input type.
7420
7421 >>> a = np.array([[1, 2] ,[3, 4]])
7422 >>> ma.resize(a, (3, 3))
7423 masked_array(
7424 data=[[1, 2, 3],
7425 [4, 1, 2],
7426 [3, 4, 1]],
7427 mask=False,
7428 fill_value=999999)
7429
7430 """
7431 # We can't use _frommethods here, as N.resize is notoriously whiny.
7432 m = getmask(x)
7433 if m is not nomask:
7434 m = np.resize(m, new_shape)

Callers 6

test_testCopySizeMethod · 0.90
test_copyMethod · 0.90
Array1Method · 0.50
ArrayZMethod · 0.50
Array2Method · 0.50
resizeMethod · 0.50

Calls 4

getmaskFunction · 0.85
get_masked_subclassFunction · 0.85
resizeMethod · 0.45
viewMethod · 0.45

Tested by 6

test_testCopySizeMethod · 0.72
test_copyMethod · 0.72
Array1Method · 0.40
ArrayZMethod · 0.40
Array2Method · 0.40
resizeMethod · 0.40