Difference between revisions of "CopyIndex"
Line 8: | Line 8: | ||
[[CopyIndex]] is most often used to make a copy of an existing index for the purpose of defining a new index with the same index values. For example, if you need to represent a square matrix, you will need two indexes with the same length -- defining the second using [[CopyIndex]] allows the second index to automatically adapt if the first index changes. | [[CopyIndex]] is most often used to make a copy of an existing index for the purpose of defining a new index with the same index values. For example, if you need to represent a square matrix, you will need two indexes with the same length -- defining the second using [[CopyIndex]] allows the second index to automatically adapt if the first index changes. | ||
− | = Library = | + | == Library == |
Array Functions | Array Functions | ||
− | = Examples = | + | == Examples == |
Index Origins | Index Origins | ||
Line 24: | Line 24: | ||
Note: If you were to define ''Destinations'' simply as ''Origins'', without using [[CopyIndex]](), ''Destinations'' would be indexed by ''Origins'', and the resulting table would have only one dimension index. By defining ''Destinations'' with [[CopyIndex]](), it becomes a separate index, so that the table has two dimensions. | Note: If you were to define ''Destinations'' simply as ''Origins'', without using [[CopyIndex]](), ''Destinations'' would be indexed by ''Origins'', and the resulting table would have only one dimension index. By defining ''Destinations'' with [[CopyIndex]](), it becomes a separate index, so that the table has two dimensions. | ||
− | = Notes = | + | == Notes == |
When defining a local index using [[Index..Do]], a [[CopyIndex]] is implicitly performed, so an explicit call to [[CopyIndex]] is unnecessary. | When defining a local index using [[Index..Do]], a [[CopyIndex]] is implicitly performed, so an explicit call to [[CopyIndex]] is unnecessary. | ||
− | = See Also = | + | == See Also == |
* [[Index..Do]] | * [[Index..Do]] | ||
* [[Subset]] | * [[Subset]] | ||
* [[Array]] | * [[Array]] | ||
+ | |||
+ | =User Guide= | ||
+ | Makes a copy of the values of index '''i''', to be assigned to a new index variable, global or local. For example, suppose you want to create a matrix of distances between a set of origins and destinations, which are each the same set of cities: | ||
+ | |||
+ | Index Origins | ||
+ | Definition:= ['London', 'New York', 'Tokyo', 'Paris', 'Delhi'] | ||
+ | Index Destinations | ||
+ | Definition:= CopyIndex(Origins) | ||
+ | |||
+ | Variable Flight_times := Table(Origins, Destinations) | ||
+ | |||
+ | If you defined <tt>Destinations</tt> as equal to <tt>Origins</tt>, without using '''Copyindex()''', <tt>Destinations</tt> would be indexed by <tt>Origins</tt>, and the resulting table would have only one dimension index. By defining <tt>Destinations</tt> with '''CopyIndex()''', it becomes a separate index, so that the | ||
+ | table has two dimensions. |
Revision as of 18:32, 30 July 2015
CopyIndex(i)
Makes a copy of the values in «i» and returns these as a list. «i» must be a list or 1-D array. In the case of a 1-D array, the values in the array itself are returned, essentially removing the index from the array (converting the array to a list, or equivalently, to an array with an implicit dimension).
CopyIndex is most often used to make a copy of an existing index for the purpose of defining a new index with the same index values. For example, if you need to represent a square matrix, you will need two indexes with the same length -- defining the second using CopyIndex allows the second index to automatically adapt if the first index changes.
Library
Array Functions
Examples
Index Origins Definition := [ 'London', 'New York', 'Tokyo', 'Paris', 'Delhi' ] Index Destinations Definition := CopyIndex( Origins ) Variable Flight_times := Table(Origins,Destinations)
Note: If you were to define Destinations simply as Origins, without using CopyIndex(), Destinations would be indexed by Origins, and the resulting table would have only one dimension index. By defining Destinations with CopyIndex(), it becomes a separate index, so that the table has two dimensions.
Notes
When defining a local index using Index..Do, a CopyIndex is implicitly performed, so an explicit call to CopyIndex is unnecessary.
See Also
User Guide
Makes a copy of the values of index i, to be assigned to a new index variable, global or local. For example, suppose you want to create a matrix of distances between a set of origins and destinations, which are each the same set of cities:
Index Origins Definition:= ['London', 'New York', 'Tokyo', 'Paris', 'Delhi'] Index Destinations Definition:= CopyIndex(Origins)
Variable Flight_times := Table(Origins, Destinations)
If you defined Destinations as equal to Origins, without using Copyindex(), Destinations would be indexed by Origins, and the resulting table would have only one dimension index. By defining Destinations with CopyIndex(), it becomes a separate index, so that the table has two dimensions.
Enable comment auto-refresher