Difference between revisions of "EGR 103/Fall 2018/Sandbox"
Jump to navigation
Jump to search
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | == Introduction == | ||
+ | This page will be for random snippets of code that come up during the semester | ||
+ | |||
+ | == Sandbox == | ||
+ | |||
* Note the differences between the following ways of adding to a list: | * Note the differences between the following ways of adding to a list: | ||
:<source lang=python> | :<source lang=python> | ||
Line 14: | Line 19: | ||
</source> | </source> | ||
: creates | : creates | ||
− | < | + | <source lang=python> |
['hello', 'there'] | ['hello', 'there'] | ||
</source> | </source> | ||
− | * np.where(BOOLEAN) returns a tuple; to get to the actual indices, you need np.where(BOOLEAN)[0]. If you specifically only want the first place something is try in the BOOLEAN, use you need np.where(BOOLEAN)[0][0]. | + | * <code>np.where(BOOLEAN)</code> returns a tuple; to get to the actual indices, you need <code>np.where(BOOLEAN)[0]</code>. If you specifically only want the first place something is try in the BOOLEAN, use you need <code>np.where(BOOLEAN)[0][0]</code>. |
Latest revision as of 14:48, 15 October 2018
Introduction
This page will be for random snippets of code that come up during the semester
Sandbox
- Note the differences between the following ways of adding to a list:
as_letters = ['hello'] as_letters += 'there'
- creates
['hello', 't', 'h', 'e', 'r', 'e']
- while
as_word = ['hello'] as_word += ['there']
- creates
['hello', 'there']
np.where(BOOLEAN)
returns a tuple; to get to the actual indices, you neednp.where(BOOLEAN)[0]
. If you specifically only want the first place something is try in the BOOLEAN, use you neednp.where(BOOLEAN)[0][0]
.