Remove small Poly series coefficients. Parameters ---------- seq : sequence Sequence of Poly series coefficients. This routine fails for empty sequences. Returns ------- series : sequence Subsequence with trailing zeros removed. If the resulting sequ
(seq)
| 52 | # Helper functions to convert inputs to 1-D arrays |
| 53 | # |
| 54 | def trimseq(seq): |
| 55 | """Remove small Poly series coefficients. |
| 56 | |
| 57 | Parameters |
| 58 | ---------- |
| 59 | seq : sequence |
| 60 | Sequence of Poly series coefficients. This routine fails for |
| 61 | empty sequences. |
| 62 | |
| 63 | Returns |
| 64 | ------- |
| 65 | series : sequence |
| 66 | Subsequence with trailing zeros removed. If the resulting sequence |
| 67 | would be empty, return the first element. The returned sequence may |
| 68 | or may not be a view. |
| 69 | |
| 70 | Notes |
| 71 | ----- |
| 72 | Do not lose the type info if the sequence contains unknown objects. |
| 73 | |
| 74 | """ |
| 75 | if len(seq) == 0: |
| 76 | return seq |
| 77 | else: |
| 78 | for i in range(len(seq) - 1, -1, -1): |
| 79 | if seq[i] != 0: |
| 80 | break |
| 81 | return seq[:i+1] |
| 82 | |
| 83 | |
| 84 | def as_series(alist, trim=True): |