Base.copy

Base.copy(to=None, rowsArePoints=True, outputAs1D=False)

Duplicate an object. Optionally to another nimble or raw format.

Return a new object containing the same data as this object. When copying to a nimble format, the pointNames and featureNames will also be copied, as well as any name and path metadata. A deep copy is made in all cases, no references are shared between this object and the copy.

Parameters:
  • to (str, None) – If None, will return a copy of this object. To return a different type of nimble Base object, specify to: ‘List’, ‘Matrix’, ‘Sparse’ or ‘DataFrame’. To specify a raw return type (which will not include point or feature names), specify to: ‘python list’, ‘numpy array’, ‘numpy matrix’, ‘scipy csr’, ‘scipy csc’, ‘scipy coo’, ‘pandas dataframe’, ‘list of dict’ or ‘dict of list’.

  • rowsArePoints (bool) – Define whether the rows of the output object correspond to the points in this object. Default is True, if False the returned copy will transpose the data filling each row with feature data.

  • outputAs1D (bool) – Return a one-dimensional object. Default is False, True is only a valid input for ‘python list’ and ‘numpy array’, all other formats must be two-dimensional.

Returns:

object – A copy of this object. If to is not None, the copy will be in the specified format.

Examples

Copy this object in the same format.

>>> lst = [[1, 3, 5], [2, 4, 6]]
>>> ptNames = ['odd', 'even']
>>> X = nimble.data(lst, pointNames=ptNames,
...                 name="odd&even")
>>> X
<Matrix "odd&even" 2pt x 3ft
        0  1  2
      ┌────────
  odd │ 1  3  5
 even │ 2  4  6
>
>>> XCopy = X.copy()
>>> XCopy
<Matrix "odd&even" 2pt x 3ft
        0  1  2
      ┌────────
  odd │ 1  3  5
 even │ 2  4  6
>

Copy to other formats.

>>> ptNames = ['0', '1']
>>> ftNames = ['a', 'b']
>>> X = nimble.identity(2, pointNames=ptNames,
...                     featureNames=ftNames)
>>> asDataFrame = X.copy(to='DataFrame')
>>> asDataFrame
<DataFrame 2pt x 2ft
     a  b
   ┌─────
 0 │ 1  0
 1 │ 0  1
>
>>> asNumpyArray = X.copy(to='numpy array')
>>> asNumpyArray
array([[1, 0],
       [0, 1]])
>>> asListOfDict = X.copy(to='list of dict')
>>> asListOfDict
[{'a': 1, 'b': 0}, {'a': 0, 'b': 1}]

Keywords: duplicate, raw, replicate, convert, change, clone