\section ExamplesArrays Arrays \subsection ExamplesArraysCreate Create \anchor BEGIN_PYTHON_ONLY \subsubsection MEDCouplingArraySteps0 Building an array from scratch in Python \anchor MEDCouplingArraySteps0Double

Building a double array from scratch in Python

Let's consider a list of floats \c dataDouble. \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_0 The easiest way to build the \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble instance" called \c arrayDouble simply call : \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1bis An another way is to do that : \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1 \anchor MEDCouplingArraySteps0Int

Building an int array from scratch in Python

Let's consider a list of ints \c dataInt. \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_2 The easiest way to build the \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" called \c arrayInt simply call : \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3bis An another way is to do that : \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3 \anchor END_PYTHON_ONLY \anchor BEGIN_CPP_ONLY \subsubsection MEDCouplingArraySteps1 Building an array from scratch in C++ In this example we will create arrays with 12 tuples constituted each of 3 components. These arrays will be created using different ways.\n The following code is only based using \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble" but the use of \ref ParaMEDMEM::DataArrayInt "DataArrayInt" is strictly equivalent. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_0 \anchor MEDCouplingArraySteps1NCNO

Building an array from scratch in C++, no copy no ownership

\snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_1 \anchor MEDCouplingArraySteps1NCWCPPO

Building an array from scratch in C++, no copy with C++ ownership

\snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_2 \anchor MEDCouplingArraySteps1NCWCO

Building an array from scratch in C++, no copy with C ownership

\snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_3 \anchor MEDCouplingArraySteps1WC

Building an array from scratch in C++, with copy

\snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_4 \anchor END_CPP_ONLY \anchor BEGIN_CPP_ONLY \subsubsection cpp_mcdataarray_copy Copy DataArrays \anchor cpp_mcdataarray_deepcopy

Deep copy

To perform a deep copy of a DataArray instance simply invoke : \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5 or : \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5bis \c coordsArrCpy is the deep copy of \c coordsArr so they are independent and their *raw data* has been deeply copied. So it leads to the following behaviour : \anchor MEDCouplingArrayBasicsCopyDeepTestEqual \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_6 As \c coordsArrCpy is a copy object it needs to be deallocated in C++ like \c coordsArr. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_7 \anchor cpp_mcdataarray_shallowcopy

Shallow copy

To perform a shallow copy of a DataArray instance simply invoke : \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_8 \c coordsArrCpy is the shallow copy of \c coordsArr so they share the same *raw data*. In reality they are the same object. So it leads to the following behaviour to compare with the deep copy : \anchor MEDCouplingArrayBasicsCopyShallowTestEqual \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_9 So here the content of \c coordsArr and \c coordsArrCpy are linked, contrary to the deep copy case. As \c coordsArrCpy is a copy object, in C++, it needs to be deallocated. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_10 \anchor MEDCouplingArrayBasicsCopyDeepAssign

Assignation by deep copy of DataArray

We start by building a instance of ParaMEDMEM::DataArrayDouble allocated or not. Here, instance is not allocated, only built empty. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_11 Then, \c coordsArrCpy is assigned with the content of \c coordsArr. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_12 Then \c coordsArrCpy is a deep copy of \c coordsArr except that the instance of ParaMEDMEM::DataArrayDouble is those specified. But the behaviour is the same than those seen for \ref MEDCouplingArrayBasicsCopyDeepTestEqual "deep copy". \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_13 As always, in C++, \c coordsArrCpy is an object whose life cycle is fully independent from \c coordsArr so decrement is needed. \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_14 \anchor END_CPP_ONLY \subsubsection cpp_mcdataarrayint_buildpermutationarr Building a permutation array Here we create two arrays containing same values but in different order and then we use \ref ParaMEDMEM::DataArrayInt::buildPermutationArr "DataArrayInt::buildPermutationArr()" to get an array showing in what places the values of \b b array are located in \b a array. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_buildPermutationArr_1 The result array \b c contains [1,0,4,2,3]. \subsection ExamplesArraysModify Modify \subsubsection cpp_mcdataarrayint_invertarray Inverting renumbering maps \anchor cpp_mcdataarrayint_invertarrayo2n2n2o

invertArrayO2N2N2O()

In this example we create a DataArrayInt containing a renumbering map in "Old to New" mode, convert it into the renumbering map in "New to Old" mode and check the result. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayO2N2N2O_1 \anchor cpp_mcdataarrayint_invertarrayn2o2o2n

invertArrayN2O2O2N()

In this example we create a DataArrayInt containing a renumbering map in "New to Old" mode, convert it into the renumbering map in "Old to New" mode and check the result. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayN2O2O2N_1 \subsubsection py_mcdataarraydouble_setpartofvalues Set part of values of DataArrayDouble \anchor py_mcdataarraydouble_setselectedcomponents

setSelectedComponents()

First, we create a 'source' array. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents1 Now we create a larger zero array and assign the array \b da into it. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents2 As result contents of the array \b dv are as follows.
Info of components : "a2"   "a1"   "v3"   "v4"
    Tuple #0 : 2 1 0 0
    Tuple #1 : 4 3 0 0
    Tuple #2 : 6 5 0 0
    Tuple #3 : 0 0 0 0
The same result can be achieved other way (except that component info is not copied): \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents3 \anchor py_mcdataarraydouble_setpartofvalues1

setPartOfValues1()

We create two arrays: - a "large" (4x4) zero array \b da to assign to and - a smaller (2x2) array \b dv filled with values [7.,8.,9.,10]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_1 Now we copy \b dv to the middle of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_2 As result contents of the array \b da are as follows.
    Info of components :"v1"   "v2"   "v3"   "v4"
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 8 0
    Tuple #2 : 0 9 10 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and copy \b dv into a component of \b da. Note that the last parameter \b strictCompoCompare should be \c False in this case, else \ref ParaMEDMEM::DataArrayDouble::setPartOfValues1() throws an exception because \b da has 2 components but only one target component is specified. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 8 0 0
    Tuple #2 : 0 9 0 0
    Tuple #3 : 0 10 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 8 9 10
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_5
    Tuple #0 : 0 7 0 8
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 9 0 10
    Tuple #3 : 0 0 0 0
The same result can be achieved other way: \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_6 \anchor py_mcdataarraydouble_setpartofvaluessimple1

setPartOfValuesSimple1()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_1 Now we assign \b dv to the middle of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
The same result can be achieved other way: \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_6 \anchor py_mcdataarraydouble_setpartofvaluessimple2

setPartOfValuesSimple2()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_1 Now we assign \b dv to the middle of \b da. We explicitly specify tuples and component to assign to by a list [1,2]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
\note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple2() can't be explicitly called in Python. \anchor py_mcdataarraydouble_setpartofvaluessimple3

setPartOfValuesSimple3()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_1 Now we assign \b dv to the middle of \b da. We explicitly specify tuples to assign to by a list [1,2]. And we specify components to assign to using slicing: 1:3. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
\note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple3() can't be explicitly called in Python. \anchor py_mcdataarraydouble_setpartofvalues2

setPartOfValues2()

We create two arrays: - a "large" (4x7) zero array \b da to assign to, - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_1 Now we assign the two components of \b dv to the components of \b da with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with indices [0,1,2]. This is the first mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0  7  0  8  0  0  0
    Tuple #1 : 0  9  0 10  0  0  0
    Tuple #2 : 0 11  0 12  0  0  0
    Tuple #3 : 0  0  0  0  0  0  0
Every value of \b dv has been assigned to its own location within \b da. Now we re-fill \b da with zeros and rearrange \b dv to have 6 components. And we assign \b dv to the tuples of \b da with indices [0,2,3] . This is the second mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_3 The contents of \b dv have been assigned to each of specified tuples of \b da. Every value of \b dv is repeated in the 3 specified tuples within \b da.
    Tuple #0 : 7  0  8  9 10 11 12
    Tuple #1 : 0  0  0  0  0  0  0
    Tuple #2 : 7  0  8  9 10 11 12
    Tuple #3 : 7  0  8  9 10 11 12
\note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues2() can't be explicitly called in Python. \anchor py_mcdataarraydouble_setpartofvalues3

setPartOfValues3()

We create two arrays: - a "large" (4x7) zero array \b da to assign to, - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_1 Now we assign the two components of \b dv to the components of \b da with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with indices [0,1,2] which are specified using slicing: "0:3". This is the first mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0  7  0  8  0  0  0
    Tuple #1 : 0  9  0 10  0  0  0
    Tuple #2 : 0 11  0 12  0  0  0
    Tuple #3 : 0  0  0  0  0  0  0
Every value of \b dv has been assigned to its own location within \b da. Now we re-fill \b da with zeros and rearrange \b dv to have 6 components. And we assign \b dv to the tuples of \b da with indices [0,2] using \a slice notation "0:4:2". This is the second mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_3 The contents of \b dv have been assigned to each of specified tuples of \b da. Every value of \b dv is repeated in the 3 specified tuples within \b da.
    Tuple #0 : 7  0  8  9 10 11 12
    Tuple #1 : 0  0  0  0  0  0  0
    Tuple #2 : 7  0  8  9 10 11 12
    Tuple #3 : 0  0  0  0  0  0  0
\note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues3() can't be explicitly called in Python. \subsubsection py_mcdataarrayint_setpartofvalues Set part of values of DataArrayInt \anchor py_mcdataarrayint_setselectedcomponents

setSelectedComponents()

First, we create a 'source' array. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents1 Now we create a larger zero array and assign the array \b da to it. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents2 As result contents of the array \b dv are as follows.
Info of components : "a2"   "a1"   "v3"   "v4"
    Tuple #0 : 2 1 0 0
    Tuple #1 : 4 3 0 0
    Tuple #2 : 6 5 0 0
    Tuple #3 : 0 0 0 0
The same result can be achieved other way (except that component info is not copied): \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents3 \anchor py_mcdataarrayint_setpartofvalues1

setPartOfValues1()

We create two arrays: - a "large" (4x4) zero array \b da to assign to, and - a smaller (2x2) array \b dv filled with values [7,8,9,10]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_1 Now we copy \b dv to the middle of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_2 As result contents of the array \b da are as follows.
    Info of components :"v1"   "v2"   "v3"   "v4"
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 8 0
    Tuple #2 : 0 9 10 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and copy \b dv into a component of \b da. Note that the last parameter \b strictCompoCompare should be \c False in this case, else \ref ParaMEDMEM::DataArrayInt::setPartOfValues1() throws an exception because \b da has 2 components but only one target component is specified. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 8 0 0
    Tuple #2 : 0 9 0 0
    Tuple #3 : 0 10 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 8 9 10
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_5
    Tuple #0 : 0 7 0 8
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 9 0 10
    Tuple #3 : 0 0 0 0
The same result can be achieved other way: \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_6 \anchor py_mcdataarrayint_setpartofvaluessimple1

setPartOfValuesSimple1()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_1 Now we assign \b dv to the middle of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
The same result can be achieved other way: \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_6 \anchor py_mcdataarrayint_setpartofvaluessimple2

setPartOfValuesSimple2()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_1 Now we assign \b dv to the middle of \b da. We explicitly specify tuples and component to assign to by a list [1,2]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
\note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple2() can't be explicitly called in Python. \anchor py_mcdataarrayint_setpartofvaluessimple3

setPartOfValuesSimple3()

We create an array (4x4) \b da to assign to and define a value \b dv to assign. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_1 Now we assign \b dv to the middle of \b da. We explicitly specify tuples to assign to by a list [1,2]. And we specify components to assign to using slicing: 1:3. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0 0 0 0
    Tuple #1 : 0 7 7 0
    Tuple #2 : 0 7 7 0
    Tuple #3 : 0 0 0 0
Here we re-fill \b da with zeros and assign \b dv to a component of \b da. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_3
    Tuple #0 : 0 7 0 0
    Tuple #1 : 0 7 0 0
    Tuple #2 : 0 7 0 0
    Tuple #3 : 0 7 0 0
Below more two variants of location of target values are shown. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_4
    Tuple #0 : 0 0 0 0
    Tuple #1 : 7 7 7 7
    Tuple #2 : 0 0 0 0
    Tuple #3 : 0 0 0 0
\snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_5
    Tuple #0 : 0 7 0 7
    Tuple #1 : 0 0 0 0
    Tuple #2 : 0 7 0 7
    Tuple #3 : 0 0 0 0
\note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple3() can't be explicitly called in Python. \anchor py_mcdataarrayint_setpartofvalues2

setPartOfValues2()

We create two arrays: - a "large" (4x7) zero array \b da to assign to, - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_1 Now we assign the two components of \b dv to the components of \b da with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with indices [0,1,2]. This is the first mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0  7  0  8  0  0  0
    Tuple #1 : 0  9  0 10  0  0  0
    Tuple #2 : 0 11  0 12  0  0  0
    Tuple #3 : 0  0  0  0  0  0  0
Every value of \b dv has been assigned to its own location within \b da. Now we re-fill \b da with zeros and rearrange \b dv to have 6 components. And we assign \b dv to the tuples of \b da with indices [0,2,3] . This is the second mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_3 The contents of \b dv have been assigned to each of specified tuples of \b da. Every value of \b dv is repeated in the 3 specified tuples within \b da.
    Tuple #0 : 7  0  8  9 10 11 12
    Tuple #1 : 0  0  0  0  0  0  0
    Tuple #2 : 7  0  8  9 10 11 12
    Tuple #3 : 7  0  8  9 10 11 12
\note \ref ParaMEDMEM::DataArrayInt::setPartOfValues2() can't be explicitly called in Python. \anchor py_mcdataarrayint_setpartofvalues3

setPartOfValues3()

We create two arrays: - a "large" (4x7) zero array \b da to assign to, - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12]. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_1 Now we assign the two components of \b dv to the components of \b da with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with indices [0,1,2] which are specified using slicing: "0:3". This is the first mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_2 As result contents of the array \b da are as follows.
    Tuple #0 : 0  7  0  8  0  0  0
    Tuple #1 : 0  9  0 10  0  0  0
    Tuple #2 : 0 11  0 12  0  0  0
    Tuple #3 : 0  0  0  0  0  0  0
Every value of \b dv has been assigned to its own location within \b da. Now we re-fill \b da with zeros and rearrange \b dv to have 6 components. And we assign \b dv to the tuples of \b da with indices [0,2] using \a slice notation "0:4:2". This is the second mode of usage. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_3 The contents of \b dv have been assigned to each of specified tuples of \b da. Every value of \b dv is repeated in the 3 specified tuples within \b da.
    Tuple #0 : 7  0  8  9 10 11 12
    Tuple #1 : 0  0  0  0  0  0  0
    Tuple #2 : 7  0  8  9 10 11 12
    Tuple #3 : 0  0  0  0  0  0  0
\note \ref ParaMEDMEM::DataArrayInt::setPartOfValues3() can't be explicitly called in Python. \subsubsection py_mcdataarraydouble_getdifferentvalues Excluding coincident tuples from DataArrayDouble The code below creates an array of real values and than an array of unique values, not closer one to another than 0.2, is retrieved from it. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_getDifferentValues1 \subsubsection cpp_mcdataarraydouble_meldwith Concatenating DataArrayDouble's by appending components In this example we create two data arrays including \b same number of tuples and then we concatenate them using \ref ParaMEDMEM::DataArrayDouble::meldWith "meldWith()". \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_Meld1_1 Now the array \b da1 includes 7 tuples (as before) of 3 components each. Its components are: "c0da1","c1da1","c0da2". \subsubsection cpp_mcdataarrayint_meldwith Concatenating DataArrayInt's by appending components In this example we create two data arrays including \b same number of tuples and then we concatenate them using \ref ParaMEDMEM::DataArrayInt::meldWith "meldWith()". \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_Meld1_1 Now the array \b da1 includes 7 tuples (as before) of 3 components each. Its components are: "c0da1","c1da1","c0da2". \subsection ExamplesArraysAccess Access \subsubsection cpp_mcdataarrayint_getTuple Getting a tuple of DataArrayInt In this simple example we create an array of integers arranged into 3 tuples per 2 components, and finally print the second tuple. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_1 The output is
 [9, 10] 
Note that we can traverse all tuples in the array by simply iterating over it as the code below does. \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_2 Its output follows.
(7, 8)
(9, 10)
(11, 12)
\subsubsection cpp_mcdataarraydouble_getidsinrange Finding values in range in DataArrayDouble In this example we create an array \b da containing same values as ones returned by \c range( \c 10 ). Then we get an array of indices of values of \b da being in range [ 2.5, 6 ]. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_getIdsInRange_1 As result contents of the array \b da2 are as follows.
    Tuple #0 : 3
    Tuple #1 : 4
    Tuple #2 : 5
    Tuple #3 : 6
\subsubsection cpp_mcdataarraydouble_findcommontuples Finding coincident tuples in DataArrayDouble Let's create an array of 6 tuples and 2 components that can be considered as coordinates of 6 points in 2D space. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples1 Now we find points that are not far each from other than 1e-1. \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples2 As we can realize from the above code, a hardcoded array \b expected3 is equal to the raw data of a DataArrayInt \b c and a hardcoded array \b expected4 is equal to the raw data of the DataArrayInt \b cI. The array \b c contains indices of 5 coincident points. The array \b cI shows us boundaries of (cI->getNumberOfTuples()-1) = 2 groups of coincident points: - The first group starts at index 0 and includes (3 - 0) = 3 points: 0,3,4. - The second group starts at index 3 and includes (5 - 3) = 2 points: 1,2. \subsubsection py_mcdataarraydouble_KeepSelectedComponents Creation of a sub-part of the DataArrayDouble by selecting components \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_1 We created an array \b a1 containing 5 tuples of 4 components each (20 values). Now we are going to create an array \b a2 containing some components of \b a1. \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_2 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus the result array \b a2 includes 30 elements (5 tuples per 6 components). \subsubsection py_mcdataarrayint_keepselectedcomponents Creation of a sub-part of the DataArrayInt by selecting components \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_1 We created an array \b a1 containing 5 tuples of 4 components each (20 values). Now we are going to create an array \b a2 containing some components of \b a1. \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_2 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus the result array \b a2 includes 30 elements (5 tuples per 6 components). Note that \ref ParaMEDMEM::DataArrayInt::keepSelectedComponents() "DataArrayInt::keepSelectedComponents()" is called, providing the same result, by the following python code: \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_3