Remove small Poly series coefficients. Parameters ---------- seq : sequence Sequence of Poly series coefficients. Returns ------- series : sequence Subsequence with trailing zeros removed. If the resulting sequence would be empty, return the first el
(seq)
| 32 | # Helper functions to convert inputs to 1-D arrays |
| 33 | # |
| 34 | def trimseq(seq): |
| 35 | """Remove small Poly series coefficients. |
| 36 | |
| 37 | Parameters |
| 38 | ---------- |
| 39 | seq : sequence |
| 40 | Sequence of Poly series coefficients. |
| 41 | |
| 42 | Returns |
| 43 | ------- |
| 44 | series : sequence |
| 45 | Subsequence with trailing zeros removed. If the resulting sequence |
| 46 | would be empty, return the first element. The returned sequence may |
| 47 | or may not be a view. |
| 48 | |
| 49 | Notes |
| 50 | ----- |
| 51 | Do not lose the type info if the sequence contains unknown objects. |
| 52 | |
| 53 | """ |
| 54 | if len(seq) == 0 or seq[-1] != 0: |
| 55 | return seq |
| 56 | else: |
| 57 | for i in range(len(seq) - 1, -1, -1): |
| 58 | if seq[i] != 0: |
| 59 | break |
| 60 | return seq[:i + 1] |
| 61 | |
| 62 | |
| 63 | def as_series(alist, trim=True): |