Reference · Vectors
vec.pow
signature
vec.pow(list, num) -> listWhat it does
Each item raised to a power. The result is always a list of floats, even for ints to a
whole power: vec.pow([2, 3], 2) is [4.0, 9.0]. A fractional power takes a root, so
vec.pow(xs, 0.5) is vec.sqrt(xs).
Examples
print(vec.pow([1, 2, 3], 2))print(vec.pow([4, 9], 0.5))print(vec.pow([2, 3], 3))output
[1.0, 4.0, 9.0][2.0, 3.0][8.0, 27.0]Edge cases
- A negative number to a fractional power is
NaN, not an error. xto the power 0 is1.0, for 0 too; a negative power gives the reciprocal.- The empty list gives the empty list.
- A power past what a float holds is
inf.
print(vec.pow([-8], 1 / 3), vec.pow([-2], 0.5))print(vec.pow([0, 5], 0), vec.pow([2, 4], -1))print(vec.pow([], 2))print(vec.pow([10], 400))output
[NaN] [NaN][1.0, 1.0] [0.5, 0.25][][inf]Errors
A list with an item that is not an int or a float, a missing or non-numeric power, or a first argument that is not a list are runtime errors, not error values.
this one fails
print(vec.pow([1, "a"], 2))output
line 1: `vec.pow` expects a list of numbers, but item 1 is strthis one fails
print(vec.pow([1, 2]))output
line 1: `vec.pow` expects a number as argument 2, got nothingChaining
xs | vec.pow(2) squares a list; summed, it is the squared length:
print(vec.arange(1, 4) | vec.pow(2) | sum)print([3, 4] | vec.pow(2) | sum | math.sqrt)output
14.05.0See also
vec.sqrt, vec.exp, vec.mul, vec.norm, math.pow
Thread
Thread 0 posts
On vec.pow(): questions, tips, corrections, and code that uses it.
No posts yet. The first one opens the thread.
Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo