2 \section ExamplesArrays Arrays
4 \subsection ExamplesArraysCreate Create
6 \anchor BEGIN_PYTHON_ONLY
7 \subsubsection MEDCouplingArraySteps0 Building an array from scratch in Python
8 \anchor MEDCouplingArraySteps0Double
9 <h3>Building a double array from scratch in Python</h3>
11 Let's consider a list of floats \c dataDouble.
13 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_0
15 The easiest way to build the \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble instance" called \c arrayDouble simply call :
17 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1bis
19 An another way is to do that :
21 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_1
23 \anchor MEDCouplingArraySteps0Int
24 <h3>Building an int array from scratch in Python</h3>
26 Let's consider a list of ints \c dataInt.
28 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_2
30 The easiest way to build the \ref ParaMEDMEM::DataArrayInt "DataArrayInt instance" called \c arrayInt simply call :
32 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3bis
34 An another way is to do that :
36 \snippet MEDCouplingExamplesTest.py PySnippetDataArrayBuild1_3
37 \anchor END_PYTHON_ONLY
40 \anchor BEGIN_CPP_ONLY
41 \subsubsection MEDCouplingArraySteps1 Building an array from scratch in C++
43 In this example we will create arrays with 12 tuples constituted each
44 of 3 components. These arrays will be created using different ways.\n
46 The following code is only based using \ref ParaMEDMEM::DataArrayDouble "DataArrayDouble"
47 but the use of \ref ParaMEDMEM::DataArrayInt "DataArrayInt" is strictly equivalent.
49 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_0
51 \anchor MEDCouplingArraySteps1NCNO
52 <h3>Building an array from scratch in C++, no copy no ownership</h3>
54 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_1
56 \anchor MEDCouplingArraySteps1NCWCPPO
57 <h3>Building an array from scratch in C++, no copy with C++ ownership</h3>
59 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_2
61 \anchor MEDCouplingArraySteps1NCWCO
62 <h3>Building an array from scratch in C++, no copy with C ownership</h3>
64 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_3
66 \anchor MEDCouplingArraySteps1WC
67 <h3>Building an array from scratch in C++, with copy</h3>
69 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_4
72 \anchor BEGIN_CPP_ONLY
73 \subsubsection cpp_mcdataarray_copy Copy DataArrays
75 \anchor cpp_mcdataarray_deepcopy
78 To perform a deep copy of a DataArray instance simply invoke :
80 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5
84 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_5bis
86 \c coordsArrCpy is the deep copy of \c coordsArr so they are independent and their *raw data* has been deeply copied.
88 So it leads to the following behaviour :
89 \anchor MEDCouplingArrayBasicsCopyDeepTestEqual
91 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_6
93 As \c coordsArrCpy is a copy object it needs to be deallocated in C++ like \c coordsArr.
95 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_7
97 \anchor cpp_mcdataarray_shallowcopy
100 To perform a shallow copy of a DataArray instance simply invoke :
102 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_8
104 \c coordsArrCpy is the shallow copy of \c coordsArr so they share the same *raw data*. In reality they are the same object.
105 So it leads to the following behaviour to compare with the deep copy :
107 \anchor MEDCouplingArrayBasicsCopyShallowTestEqual
109 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_9
111 So here the content of \c coordsArr and \c coordsArrCpy are linked, contrary to the deep copy case.
113 As \c coordsArrCpy is a copy object, in C++, it needs to be deallocated.
115 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_10
117 \anchor MEDCouplingArrayBasicsCopyDeepAssign
118 <h3>Assignation by deep copy of DataArray</h3>
120 We start by building a instance of ParaMEDMEM::DataArrayDouble allocated or not. Here, instance is not allocated, only built empty.
122 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_11
124 Then, \c coordsArrCpy is assigned with the content of \c coordsArr.
126 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_12
128 Then \c coordsArrCpy is a deep copy of \c coordsArr except that the instance of ParaMEDMEM::DataArrayDouble is those specified.
129 But the behaviour is the same than those seen for \ref MEDCouplingArrayBasicsCopyDeepTestEqual "deep copy".
131 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_13
133 As always, in C++, \c coordsArrCpy is an object whose life cycle is fully independent from \c coordsArr so decrement is needed.
135 \snippet MEDCouplingExamplesTest.cxx CppSnippetDataArrayBuild1_14
140 \subsubsection cpp_mcdataarrayint_buildpermutationarr Building a permutation array
142 Here we create two arrays containing same values but in different order and then we use
143 \ref ParaMEDMEM::DataArrayInt::buildPermutationArr "DataArrayInt::buildPermutationArr()" to get
144 an array showing in what places the values of \b b array are located in \b a array.
145 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_buildPermutationArr_1
146 The result array \b c contains [1,0,4,2,3].
149 \subsection ExamplesArraysModify Modify
151 \subsubsection cpp_mcdataarrayint_invertarray Inverting renumbering maps
153 \anchor cpp_mcdataarrayint_invertarrayo2n2n2o
154 <h3> invertArrayO2N2N2O() </h3>
156 In this example we create a DataArrayInt containing a renumbering map in
157 "Old to New" mode, convert it into the renumbering map in "New to Old" mode and check the
159 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayO2N2N2O_1
161 \anchor cpp_mcdataarrayint_invertarrayn2o2o2n
162 <br><h3> invertArrayN2O2O2N() </h3>
164 In this example we create a DataArrayInt containing a renumbering map in
165 "New to Old" mode, convert it into the renumbering map in "Old to New" mode and check the
167 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_invertArrayN2O2O2N_1
170 \subsubsection py_mcdataarraydouble_setpartofvalues Set part of values of DataArrayDouble
172 \anchor py_mcdataarraydouble_setselectedcomponents
173 <h3> setSelectedComponents() </h3>
174 First, we create a 'source' array.
175 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents1
176 Now we create a larger zero array and assign the array \b da into it.
177 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents2
178 As result contents of the array \b dv are as follows.
180 Info of components : "a2" "a1" "v3" "v4"
186 The same result can be achieved other way (except that component info
188 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setSelectedComponents3
190 \anchor py_mcdataarraydouble_setpartofvalues1
191 <br><h3> setPartOfValues1() </h3>
192 We create two arrays:
193 - a "large" (4x4) zero array \b da to assign to and
194 - a smaller (2x2) array \b dv filled with values [7.,8.,9.,10].
196 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_1
197 Now we copy \b dv to the middle of \b da.
198 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_2
199 As result contents of the array \b da are as follows.
201 Info of components :"v1" "v2" "v3" "v4"
208 Here we re-fill \b da with zeros and copy \b dv into a component of \b da.
210 Note that the last parameter \b strictCompoCompare should be \c False
211 in this case, else \ref ParaMEDMEM::DataArrayDouble::setPartOfValues1()
212 throws an exception because \b da has 2 components but only one target
213 component is specified.
214 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_3
221 Below more two variants of location of target values are shown.
222 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_4
230 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_5
237 The same result can be achieved other way:
238 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues1_6
241 \anchor py_mcdataarraydouble_setpartofvaluessimple1
242 <br><h3> setPartOfValuesSimple1() </h3>
243 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
244 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_1
245 Now we assign \b dv to the middle of \b da.
246 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_2
247 As result contents of the array \b da are as follows.
255 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
256 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_3
263 Below more two variants of location of target values are shown.
264 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_4
272 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_5
279 The same result can be achieved other way:
280 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple1_6
283 \anchor py_mcdataarraydouble_setpartofvaluessimple2
284 <br><h3> setPartOfValuesSimple2() </h3>
285 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
286 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_1
287 Now we assign \b dv to the middle of \b da.
288 We explicitly specify tuples and component to assign to by a list [1,2].
289 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_2
290 As result contents of the array \b da are as follows.
298 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
299 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_3
306 Below more two variants of location of target values are shown.
307 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_4
315 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple2_5
322 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple2() can't
323 be explicitly called in Python.
326 \anchor py_mcdataarraydouble_setpartofvaluessimple3
327 <br><h3> setPartOfValuesSimple3() </h3>
328 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
329 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_1
330 Now we assign \b dv to the middle of \b da.
331 We explicitly specify tuples to assign to by a list [1,2]. And we specify
332 components to assign to using slicing: 1:3.
333 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_2
334 As result contents of the array \b da are as follows.
342 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
343 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_3
350 Below more two variants of location of target values are shown.
351 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_4
359 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValuesSimple3_5
366 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValuesSimple3() can't
367 be explicitly called in Python.
370 \anchor py_mcdataarraydouble_setpartofvalues2
371 <br><h3> setPartOfValues2() </h3>
372 We create two arrays:
373 - a "large" (4x7) zero array \b da to assign to,
374 - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.].
376 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_1
377 Now we assign the two components of \b dv to the components of \b da
378 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
379 indices [0,1,2]. This is the first mode of usage.
380 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_2
381 As result contents of the array \b da are as follows.
383 Tuple #0 : 0 7 0 8 0 0 0
384 Tuple #1 : 0 9 0 10 0 0 0
385 Tuple #2 : 0 11 0 12 0 0 0
386 Tuple #3 : 0 0 0 0 0 0 0
388 Every value of \b dv has been assigned to its own location within \b da.
390 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
391 And we assign \b dv to the tuples of \b da with indices [0,2,3] .
392 This is the second mode of usage.
393 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues2_3
394 The contents of \b dv have been assigned to each of specified tuples of \b da.
395 Every value of \b dv is repeated in the 3 specified tuples within \b da.
397 Tuple #0 : 7 0 8 9 10 11 12
398 Tuple #1 : 0 0 0 0 0 0 0
399 Tuple #2 : 7 0 8 9 10 11 12
400 Tuple #3 : 7 0 8 9 10 11 12
402 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues2() can't
403 be explicitly called in Python.
406 \anchor py_mcdataarraydouble_setpartofvalues3
407 <br><h3> setPartOfValues3() </h3>
408 We create two arrays:
409 - a "large" (4x7) zero array \b da to assign to,
410 - a smaller (3x2) array \b dv filled with values [7.,8.,9.,10.,11.,12.].
412 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_1
413 Now we assign the two components of \b dv to the components of \b da
414 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
415 indices [0,1,2] which are specified using slicing: "0:3".
416 This is the first mode of usage.
417 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_2
418 As result contents of the array \b da are as follows.
420 Tuple #0 : 0 7 0 8 0 0 0
421 Tuple #1 : 0 9 0 10 0 0 0
422 Tuple #2 : 0 11 0 12 0 0 0
423 Tuple #3 : 0 0 0 0 0 0 0
425 Every value of \b dv has been assigned to its own location within \b da.
427 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
428 And we assign \b dv to the tuples of \b da with indices [0,2] using \a
429 slice notation "0:4:2". This is the second mode of usage.
430 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_setPartOfValues3_3
431 The contents of \b dv have been assigned to each of specified tuples of \b da.
432 Every value of \b dv is repeated in the 3 specified tuples within \b da.
434 Tuple #0 : 7 0 8 9 10 11 12
435 Tuple #1 : 0 0 0 0 0 0 0
436 Tuple #2 : 7 0 8 9 10 11 12
437 Tuple #3 : 0 0 0 0 0 0 0
439 \note \ref ParaMEDMEM::DataArrayDouble::setPartOfValues3() can't
440 be explicitly called in Python.
443 \subsubsection py_mcdataarrayint_setpartofvalues Set part of values of DataArrayInt
445 \anchor py_mcdataarrayint_setselectedcomponents
446 <h3> setSelectedComponents() </h3>
447 First, we create a 'source' array.
448 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents1
449 Now we create a larger zero array and assign the array \b da to it.
450 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents2
451 As result contents of the array \b dv are as follows.
453 Info of components : "a2" "a1" "v3" "v4"
459 The same result can be achieved other way (except that component info
461 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setSelectedComponents3
463 \anchor py_mcdataarrayint_setpartofvalues1
464 <br><h3> setPartOfValues1() </h3>
465 We create two arrays:
466 - a "large" (4x4) zero array \b da to assign to, and
467 - a smaller (2x2) array \b dv filled with values [7,8,9,10].
469 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_1
470 Now we copy \b dv to the middle of \b da.
471 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_2
472 As result contents of the array \b da are as follows.
474 Info of components :"v1" "v2" "v3" "v4"
481 Here we re-fill \b da with zeros and copy \b dv into a component of \b da.
483 Note that the last parameter \b strictCompoCompare should be \c False
484 in this case, else \ref ParaMEDMEM::DataArrayInt::setPartOfValues1()
485 throws an exception because \b da has 2 components but only one target
486 component is specified.
487 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_3
494 Below more two variants of location of target values are shown.
495 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_4
503 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_5
510 The same result can be achieved other way:
511 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues1_6
515 \anchor py_mcdataarrayint_setpartofvaluessimple1
516 <br><h3> setPartOfValuesSimple1() </h3>
517 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
518 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_1
519 Now we assign \b dv to the middle of \b da.
520 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_2
521 As result contents of the array \b da are as follows.
529 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
530 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_3
537 Below more two variants of location of target values are shown.
538 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_4
546 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_5
553 The same result can be achieved other way:
554 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple1_6
557 \anchor py_mcdataarrayint_setpartofvaluessimple2
558 <br><h3> setPartOfValuesSimple2() </h3>
559 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
560 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_1
561 Now we assign \b dv to the middle of \b da.
562 We explicitly specify tuples and component to assign to by a list [1,2].
563 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_2
564 As result contents of the array \b da are as follows.
572 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
573 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_3
580 Below more two variants of location of target values are shown.
581 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_4
589 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple2_5
596 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple2() can't
597 be explicitly called in Python.
600 \anchor py_mcdataarrayint_setpartofvaluessimple3
601 <br><h3> setPartOfValuesSimple3() </h3>
602 We create an array (4x4) \b da to assign to and define a value \b dv to assign.
603 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_1
604 Now we assign \b dv to the middle of \b da.
605 We explicitly specify tuples to assign to by a list [1,2]. And we specify
606 components to assign to using slicing: 1:3.
607 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_2
608 As result contents of the array \b da are as follows.
616 Here we re-fill \b da with zeros and assign \b dv to a component of \b da.
617 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_3
624 Below more two variants of location of target values are shown.
625 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_4
633 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValuesSimple3_5
640 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValuesSimple3() can't
641 be explicitly called in Python.
644 \anchor py_mcdataarrayint_setpartofvalues2
645 <br><h3> setPartOfValues2() </h3>
646 We create two arrays:
647 - a "large" (4x7) zero array \b da to assign to,
648 - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12].
650 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_1
651 Now we assign the two components of \b dv to the components of \b da
652 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
653 indices [0,1,2]. This is the first mode of usage.
654 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_2
655 As result contents of the array \b da are as follows.
657 Tuple #0 : 0 7 0 8 0 0 0
658 Tuple #1 : 0 9 0 10 0 0 0
659 Tuple #2 : 0 11 0 12 0 0 0
660 Tuple #3 : 0 0 0 0 0 0 0
662 Every value of \b dv has been assigned to its own location within \b da.
664 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
665 And we assign \b dv to the tuples of \b da with indices [0,2,3] .
666 This is the second mode of usage.
667 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues2_3
668 The contents of \b dv have been assigned to each of specified tuples of \b da.
669 Every value of \b dv is repeated in the 3 specified tuples within \b da.
671 Tuple #0 : 7 0 8 9 10 11 12
672 Tuple #1 : 0 0 0 0 0 0 0
673 Tuple #2 : 7 0 8 9 10 11 12
674 Tuple #3 : 7 0 8 9 10 11 12
676 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValues2() can't
677 be explicitly called in Python.
680 \anchor py_mcdataarrayint_setpartofvalues3
681 <br><h3> setPartOfValues3() </h3>
682 We create two arrays:
683 - a "large" (4x7) zero array \b da to assign to,
684 - a smaller (3x2) array \b dv filled with values [7,8,9,10,11,12].
686 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_1
687 Now we assign the two components of \b dv to the components of \b da
688 with indices [1,3], and the 3 tuples of \b dv to the 3 tuples of \b da with
689 indices [0,1,2] which are specified using slicing: "0:3".
690 This is the first mode of usage.
691 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_2
692 As result contents of the array \b da are as follows.
694 Tuple #0 : 0 7 0 8 0 0 0
695 Tuple #1 : 0 9 0 10 0 0 0
696 Tuple #2 : 0 11 0 12 0 0 0
697 Tuple #3 : 0 0 0 0 0 0 0
699 Every value of \b dv has been assigned to its own location within \b da.
701 Now we re-fill \b da with zeros and rearrange \b dv to have 6 components.
702 And we assign \b dv to the tuples of \b da with indices [0,2] using \a
703 slice notation "0:4:2". This is the second mode of usage.
704 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_setPartOfValues3_3
705 The contents of \b dv have been assigned to each of specified tuples of \b da.
706 Every value of \b dv is repeated in the 3 specified tuples within \b da.
708 Tuple #0 : 7 0 8 9 10 11 12
709 Tuple #1 : 0 0 0 0 0 0 0
710 Tuple #2 : 7 0 8 9 10 11 12
711 Tuple #3 : 0 0 0 0 0 0 0
713 \note \ref ParaMEDMEM::DataArrayInt::setPartOfValues3() can't
714 be explicitly called in Python.
717 \subsubsection py_mcdataarraydouble_getdifferentvalues Excluding coincident tuples from DataArrayDouble
719 The code below creates an array of real values and than an array of
720 unique values, not closer one to another than 0.2, is retrieved from it.
721 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayDouble_getDifferentValues1
724 \subsubsection cpp_mcdataarraydouble_meldwith Concatenating DataArrayDouble's by appending components
726 In this example we create two data arrays including \b same number of
727 tuples and then we concatenate them using \ref
728 ParaMEDMEM::DataArrayDouble::meldWith "meldWith()".
729 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_Meld1_1
730 Now the array \b da1 includes 7 tuples (as before) of 3 components
731 each. Its components are: "c0da1","c1da1","c0da2".
734 \subsubsection cpp_mcdataarrayint_meldwith Concatenating DataArrayInt's by appending components
736 In this example we create two data arrays including \b same number of
737 tuples and then we concatenate them using \ref
738 ParaMEDMEM::DataArrayInt::meldWith "meldWith()".
739 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayInt_Meld1_1
740 Now the array \b da1 includes 7 tuples (as before) of 3 components
741 each. Its components are: "c0da1","c1da1","c0da2".
744 \subsection ExamplesArraysAccess Access
746 \subsubsection cpp_mcdataarrayint_getTuple Getting a tuple of DataArrayInt
748 In this simple example we create an array of integers arranged into 3
749 tuples per 2 components, and finally print the second tuple.
750 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_1
753 Note that we can traverse all tuples in the array by simply iterating
754 over it as the code below does.
755 \snippet MEDCouplingExamplesTest.py Snippet_DataArrayInt_getTuple_2
764 \subsubsection cpp_mcdataarraydouble_getidsinrange Finding values in range in DataArrayDouble
766 In this example we create an array \b da containing same values as ones returned by
767 \c range( \c 10 ). Then we get an array of indices of values of \b da being in
769 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_getIdsInRange_1
770 As result contents of the array \b da2 are as follows.
779 \subsubsection cpp_mcdataarraydouble_findcommontuples Finding coincident tuples in DataArrayDouble
781 Let's create an array of 6 tuples and 2 components that can be
782 considered as coordinates of 6 points in 2D space.
783 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples1
784 Now we find points that are not far each from other than 1e-1.
785 \snippet MEDCouplingExamplesTest.cxx CppSnippet_DataArrayDouble_findCommonTuples2
786 As we can realize from the above code, a hardcoded array \b expected3 is equal
787 to the raw data of a DataArrayInt \b c and a hardcoded array \b expected4 is equal
788 to the raw data of the DataArrayInt \b cI.
790 The array \b c contains indices of 5 coincident points. The array \b
791 cI shows us boundaries of (cI->getNumberOfTuples()-1) = 2 groups of coincident points:
792 - The first group starts at index 0 and includes (3 - 0) = 3 points: 0,3,4.
793 - The second group starts at index 3 and includes (5 - 3) = 2 points: 1,2.
796 \subsubsection py_mcdataarraydouble_KeepSelectedComponents Creation of a sub-part of the DataArrayDouble by selecting components
798 \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_1
799 We created an array \b a1 containing 5 tuples of 4 components each (20
800 values). Now we are going to create an array \b a2 containing some
802 \snippet MEDCouplingExamplesTest.py SnippeDataArrayDoubleKeepSelectedComponents1_2
803 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus
804 the result array \b a2 includes 30 elements (5 tuples per 6 components).
807 \subsubsection py_mcdataarrayint_keepselectedcomponents Creation of a sub-part of the DataArrayInt by selecting components
809 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_1
810 We created an array \b a1 containing 5 tuples of 4 components each (20
811 values). Now we are going to create an array \b a2 containing some
813 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_2
814 Now each tuple of \b a2 includes components named "b","c","b","c","a","a". Thus
815 the result array \b a2 includes 30 elements (5 tuples per 6 components).
818 \ref ParaMEDMEM::DataArrayInt::keepSelectedComponents() "DataArrayInt::keepSelectedComponents()"
819 is called, providing the same result, by the following python code:
820 \snippet MEDCouplingExamplesTest.py SnippeDataArrayIntKeepSelectedComponents1_3