Attachment 'terminal_7.txt'

Download

   1 Last login: Fri Jan 30 08:31:05 on ttys000
   2 odd% cd
   3 odd% cd wp/lecture/2015_01_Intro_Programming/lecture7 
   4 odd% ls
   5 pubmed.py test.txt  x.py
   6 odd% vi pubmed.py 
   7 odd% python pubmed.py 
   8   File "pubmed.py", line 26
   9 SyntaxError: Non-ASCII character '\xe2' in file pubmed.py on line 26, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
  10 odd% !vi
  11 vi pubmed.py
  12 odd% python pubmed.py
  13 Enter author name: LUDTKE SJ
  14 Traceback (most recent call last):
  15   File "pubmed.py", line 10, in <module>
  16     handle = Entrez.esearch(db="pubmed", term="{}[Author]".format(author), retmax=500)
  17   File "/Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/__init__.py", line 185, in esearch
  18     return _open(cgi, variables)
  19   File "/Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/__init__.py", line 463, in _open
  20     handle = _urlopen(cgi)
  21   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
  22     return _opener.open(url, data, timeout)
  23   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 404, in open
  24     response = self._open(req, data)
  25   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 422, in _open
  26     '_open', req)
  27   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
  28     result = func(*args)
  29   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1214, in http_open
  30     return self.do_open(httplib.HTTPConnection, req)
  31   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1184, in do_open
  32     raise URLError(err)
  33 urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
  34 odd% python pubmed.py
  35 Enter author name: ludtke sj
  36 /Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/Parser.py:525: UserWarning: Unable to load DTD file esearch.dtd.
  37 
  38 Bio.Entrez uses NCBI's DTD files to parse XML files returned by NCBI Entrez.
  39 Though most of NCBI's DTD files are included in the Biopython distribution,
  40 sometimes you may find that a particular DTD file is missing. While we can
  41 access the DTD file through the internet, the parser is much faster if the
  42 required DTD files are available locally.
  43 
  44 For this purpose, please download esearch.dtd from
  45 
  46 http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd
  47 
  48 and save it either in directory
  49 
  50 /Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/DTDs
  51 
  52 or in directory
  53 
  54 /Users/stevel/.biopython/Bio/Entrez/DTDs
  55 
  56 in order for Bio.Entrez to find it.
  57 
  58 Alternatively, you can save esearch.dtd in the directory
  59 Bio/Entrez/DTDs in the Biopython distribution, and reinstall Biopython.
  60 
  61 Please also inform the Biopython developers about this missing DTD, by
  62 reporting a bug on https://github.com/biopython/biopython/issues or sign
  63 up to our mailing list and emailing us, so that we can include it with the
  64 next release of Biopython.
  65 
  66 Proceeding to access the DTD file through the internet...
  67 
  68   warnings.warn(message)
  69 Traceback (most recent call last):
  70   File "pubmed.py", line 26, in <module>
  71     coauthlast.update(r["AU"].split()[0]) 
  72 AttributeError: 'list' object has no attribute 'split'
  73 odd% !vi
  74 vi pubmed.py
  75 odd% python pubmed.py
  76 Enter author name: ludtke sj
  77 /Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/Parser.py:525: UserWarning: Unable to load DTD file esearch.dtd.
  78 
  79 Bio.Entrez uses NCBI's DTD files to parse XML files returned by NCBI Entrez.
  80 Though most of NCBI's DTD files are included in the Biopython distribution,
  81 sometimes you may find that a particular DTD file is missing. While we can
  82 access the DTD file through the internet, the parser is much faster if the
  83 required DTD files are available locally.
  84 
  85 For this purpose, please download esearch.dtd from
  86 
  87 http://eutils.ncbi.nlm.nih.gov/eutils/dtd/20060628/esearch.dtd
  88 
  89 and save it either in directory
  90 
  91 /Library/Python/2.7/site-packages/biopython-1.63-py2.7-macosx-10.9-intel.egg/Bio/Entrez/DTDs
  92 
  93 or in directory
  94 
  95 /Users/stevel/.biopython/Bio/Entrez/DTDs
  96 
  97 in order for Bio.Entrez to find it.
  98 
  99 Alternatively, you can save esearch.dtd in the directory
 100 Bio/Entrez/DTDs in the Biopython distribution, and reinstall Biopython.
 101 
 102 Please also inform the Biopython developers about this missing DTD, by
 103 reporting a bug on https://github.com/biopython/biopython/issues or sign
 104 up to our mailing list and emailing us, so that we can include it with the
 105 next release of Biopython.
 106 
 107 Proceeding to access the DTD file through the internet...
 108 
 109   warnings.warn(message)
 110 ['Dai W', 'Fu C', 'Khant HA', 'Ludtke SJ', 'Schmid MF', 'Chiu W']
 111 Traceback (most recent call last):
 112   File "pubmed.py", line 27, in <module>
 113     coauthlast.update(r["AU"].split()[0]) 
 114 AttributeError: 'list' object has no attribute 'split'
 115 odd% python
 116 Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
 117 [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
 118 Type "help", "copyright", "credits" or "license" for more information.
 119 >>> a={}
 120 >>> a=dict()
 121 >>> a
 122 {}
 123 >>> auth={}
 124 >>> a="test"
 125 >>> auth[a]+=1
 126 Traceback (most recent call last):
 127   File "<stdin>", line 1, in <module>
 128 KeyError: 'test'
 129 >>> try: auth[a]+=1
 130 ... except: auth[a]=1
 131 ... 
 132 >>> auth
 133 {'test': 1}
 134 >>> try: auth[a]+=1
 135 ... except: auth[a]=1
 136 ... 
 137 >>> auth
 138 {'test': 2}
 139 >>> auth["alpha"]=10
 140 >>> auth["beta"]=1
 141 >>> auth
 142 {'test': 2, 'alpha': 10, 'beta': 1}
 143 >>> print auth
 144 {'test': 2, 'alpha': 10, 'beta': 1}
 145 >>> authl=list(auth)
 146 >>> authl
 147 ['test', 'alpha', 'beta']
 148 >>> authl=auth.items()
 149 >>> authl
 150 [('test', 2), ('alpha', 10), ('beta', 1)]
 151 >>> authl.sort()
 152 >>> authl
 153 [('alpha', 10), ('beta', 1), ('test', 2)]
 154 >>> authl2=[(a[1],a[0]) for a in authl]
 155 >>> authl2
 156 [(10, 'alpha'), (1, 'beta'), (2, 'test')]
 157 >>> authl2.sort()
 158 >>> authl2
 159 [(1, 'beta'), (2, 'test'), (10, 'alpha')]
 160 >>> authl2.reverse()
 161 >>> authl2
 162 [(10, 'alpha'), (2, 'test'), (1, 'beta')]
 163 >>> authl2.sort(reversed=True)
 164 Traceback (most recent call last):
 165   File "<stdin>", line 1, in <module>
 166 TypeError: 'reversed' is an invalid keyword argument for this function
 167 >>> authl2.sort(reverse=True)
 168 >>> authl
 169 [('alpha', 10), ('beta', 1), ('test', 2)]
 170 >>> def f(x,y): return x[1]-y[1]
 171 ... 
 172 >>> authl.sort(f)
 173 >>> authl
 174 [('beta', 1), ('test', 2), ('alpha', 10)]
 175 >>> def f(x,y): return y[1]-x[1]
 176 ... 
 177 >>> authl.sort(f)
 178 >>> authl
 179 [('alpha', 10), ('test', 2), ('beta', 1)]
 180 >>> def f(x,y):
 181 ...  print x
 182 ...  print y
 183 ...  print "----"
 184 ...  return y[1]-x[1]
 185 ... 
 186 >>> authl.sort(f)
 187 ('test', 2)
 188 ('alpha', 10)
 189 ----
 190 ('beta', 1)
 191 ('test', 2)
 192 ----
 193 >>> a={1,2,5,7}
 194 >>> a
 195 set([1, 2, 5, 7])
 196 >>> a[0]
 197 Traceback (most recent call last):
 198   File "<stdin>", line 1, in <module>
 199 TypeError: 'set' object does not support indexing
 200 >>> for i in a:
 201 ...  print i
 202 ... 
 203 1
 204 2
 205 5
 206 7
 207 >>> 
 208 odd% 
 209 odd% vi x.py
 210 odd% python x.py
 211              2          3          4          5          6          7          8          9         10 
 212   2          4          8         16         32         64        128        256        512       1024 
 213   3          9         27         81        243        729       2187       6561      19683      59049 
 214   4         16         64        256       1024       4096      16384      65536 2.6214e+05 1.0486e+06 
 215   5         25        125        625       3125      15625      78125 3.9062e+05 1.9531e+06 9.7656e+06 
 216   6         36        216       1296       7776      46656 2.7994e+05 1.6796e+06 1.0078e+07 6.0466e+07 
 217   7         49        343       2401      16807 1.1765e+05 8.2354e+05 5.7648e+06 4.0354e+07 2.8248e+08 
 218   8         64        512       4096      32768 2.6214e+05 2.0972e+06 1.6777e+07 1.3422e+08 1.0737e+09 
 219   9         81        729       6561      59049 5.3144e+05  4.783e+06 4.3047e+07 3.8742e+08 3.4868e+09 
 220  10        100       1000      10000      1e+05      1e+06      1e+07      1e+08      1e+09      1e+10 
 221 odd% ls
 222 pubmed.py test.txt  x.py
 223 odd% cat test.txt
 224 0.0 1.0
 225 0.327194696796 0.944956946315
 226 0.61836980307 0.785887260777
 227 0.841470984808 0.540302305868
 228 0.971937901363 0.235237573303
 229 0.995407957752 -0.0957235480144
 230 0.909297426826 -0.416146836547
 231 0.723085881738 -0.69075813975
 232 0.457272626636 -0.889326568213
 233 0.14112000806 -0.9899924966
 234 -0.190567962875 -0.981674004711
 235 -0.501277048588 -0.865286842936
 236 -0.756802495308 -0.653643620864
 237 -0.929014501271 -0.370043316963
 238 -0.998954917098 -0.0457063847386
 239 -0.958924274663 0.283662185463
 240 -0.813329391568 0.581803489859
 241 -0.578198241744 0.815896312802
 242 -0.279415498199 0.96017028665
 243 0.0501270098822 0.998742851229
 244 odd% ipython
 245 Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
 246 Type "copyright", "credits" or "license" for more information.
 247 
 248 IPython 2.0.0 -- An enhanced Interactive Python.
 249 ?         -> Introduction and overview of IPython's features.
 250 %quickref -> Quick reference.
 251 help      -> Python's own help system.
 252 object?   -> Details about 'object', use 'object??' for extra details.
 253 
 254 In [1]: lines=file("test.txt","r").readlines()
 255 
 256 In [2]: linex
 257 ---------------------------------------------------------------------------
 258 NameError                                 Traceback (most recent call last)
 259 <ipython-input-2-4cef100df21b> in <module>()
 260 ----> 1 linex
 261 
 262 NameError: name 'linex' is not defined
 263 
 264 In [3]: lines
 265 Out[3]: 
 266 ['0.0 1.0\n',
 267  '0.327194696796 0.944956946315\n',
 268  '0.61836980307 0.785887260777\n',
 269  '0.841470984808 0.540302305868\n',
 270  '0.971937901363 0.235237573303\n',
 271  '0.995407957752 -0.0957235480144\n',
 272  '0.909297426826 -0.416146836547\n',
 273  '0.723085881738 -0.69075813975\n',
 274  '0.457272626636 -0.889326568213\n',
 275  '0.14112000806 -0.9899924966\n',
 276  '-0.190567962875 -0.981674004711\n',
 277  '-0.501277048588 -0.865286842936\n',
 278  '-0.756802495308 -0.653643620864\n',
 279  '-0.929014501271 -0.370043316963\n',
 280  '-0.998954917098 -0.0457063847386\n',
 281  '-0.958924274663 0.283662185463\n',
 282  '-0.813329391568 0.581803489859\n',
 283  '-0.578198241744 0.815896312802\n',
 284  '-0.279415498199 0.96017028665\n',
 285  '0.0501270098822 0.998742851229\n']
 286 
 287 In [4]: "123    
 288 Display all 320 possibilities? (y or n)
 289 %%!                        %save                      chr
 290 %%HTML                     %sc                        class
 291 %%SVG                      %store                     classmethod
 292 %%bash                     %sx                        cmp
 293 %%capture                  %system                    coerce
 294 %%debug                    %tb                        compile
 295 %%file                     %time                      complex
 296 %%html                     %timeit                    continue
 297 %%javascript               %unalias                   copyright
 298 %%latex                    %unload_ext                credits
 299 %%perl                     %who                       def
 300 %%prun                     %who_ls                    del
 301 %%pypy                     %whos                      delattr
 302 %%python                   %xdel                      dict
 303 %%python2                  %xmode                     dir
 304 %%python3                  ArithmeticError            divmod
 305 %%ruby                     AssertionError             dreload
 306 %%script                   AttributeError             elif
 307 %%sh                       BaseException              else
 308 %%svg                      BufferError                enumerate
 309 %%sx                       BytesWarning               eval
 310 %%system                   DeprecationWarning         except
 311 %%time                     EOFError                   exec
 312 %%timeit                   Ellipsis                   execfile
 313 %%writefile                EnvironmentError           exit
 314 %alias                     Exception                  file
 315 %alias_magic               False                      filter
 316 %autocall                  FloatingPointError         finally
 317 %autoindent                FutureWarning              float
 318 %automagic                 GeneratorExit              for
 319 %bookmark                  IOError                    format
 320 %cat                       ImportError                from
 321 %cd                        ImportWarning              frozenset
 322 %clear                     In                         get_ipython
 323 %colors                    IndentationError           getattr
 324 %config                    IndexError                 global
 325 %cp                        KeyError                   globals
 326 %cpaste                    KeyboardInterrupt          hasattr
 327 %debug                     LookupError                hash
 328 %dhist                     MemoryError                help
 329 %dirs                      NameError                  hex
 330 %doctest_mode              None                       id
 331 %ed                        NotImplemented             if
 332 %edit                      NotImplementedError        import
 333 %env                       OSError                    in
 334 %gui                       Out                        input
 335 %hist                      OverflowError              int
 336 %history                   PendingDeprecationWarning  intern
 337 %install_default_config    ReferenceError             is
 338 %install_ext               RuntimeError               isinstance
 339 %install_profiles          RuntimeWarning             issubclass
 340 %killbgscripts             StandardError              iter
 341 %ldir                      StopIteration              lambda
 342 %less                      SyntaxError                len
 343 %lf                        SyntaxWarning              license
 344 %lk                        SystemError                lines
 345 %ll                        SystemExit                 list
 346 %load                      TabError                   locals
 347 %load_ext                  True                       long
 348 %loadpy                    TypeError                  map
 349 %logoff                    UnboundLocalError          max
 350 %logon                     UnicodeDecodeError         memoryview
 351 %logstart                  UnicodeEncodeError         min
 352 %logstate                  UnicodeError               next
 353 %logstop                   UnicodeTranslateError      not
 354 %ls                        UnicodeWarning             object
 355 %lsmagic                   UserWarning                oct
 356 %lx                        ValueError                 open
 357 %macro                     Warning                    or
 358 %magic                     ZeroDivisionError          ord
 359 %man                       _                          pass
 360 %matplotlib                _3                         pow
 361 %mkdir                     __                         print
 362 %more                      __IPYTHON__                property
 363 %mv                        __IPYTHON__active          pubmed.py
 364 %notebook                  ___                        quit
 365 %page                      __builtin__                raise
 366 %paste                     __debug__                  range
 367 %pastebin                  __doc__                    raw_input
 368 %pdb                       __import__                 reduce
 369 %pdef                      __name__                   reload
 370 %pdoc                      __package__                repr
 371 %pfile                     _dh                        return
 372 %pinfo                     _i                         reversed
 373 %pinfo2                    _i1                        round
 374 %popd                      _i2                        set
 375 %pprint                    _i3                        setattr
 376 %precision                 _ih                        slice
 377 %profile                   _ii                        sorted
 378 %prun                      _iii                       staticmethod
 379 %psearch                   _oh                        str
 380 %psource                   _sh                        sum
 381 %pushd                     abs                        super
 382 %pwd                       all                        test.txt
 383 %pycat                     and                        try
 384 %pylab                     any                        tuple
 385 %quickref                  apply                      type
 386 %recall                    as                         unichr
 387 %rehashx                   assert                     unicode
 388 %reload_ext                basestring                 vars
 389 %rep                       bin                        while
 390 %rerun                     bool                       with
 391 %reset                     break                      x.py
 392 %reset_selective           buffer                     xrange
 393 %rm                        bytearray                  yield
 394 %rmdir                     bytes                      zip
 395 %run                       callable                   
 396 
 397 In [4]: "123      444".split()
 398 Out[4]: ['123', '444']
 399 
 400 In [5]: lines=file("test.txt","r").read()
 401 
 402 In [6]: lines
 403 Out[6]: '0.0 1.0\n0.327194696796 0.944956946315\n0.61836980307 0.785887260777\n0.841470984808 0.540302305868\n0.971937901363 0.235237573303\n0.995407957752 -0.0957235480144\n0.909297426826 -0.416146836547\n0.723085881738 -0.69075813975\n0.457272626636 -0.889326568213\n0.14112000806 -0.9899924966\n-0.190567962875 -0.981674004711\n-0.501277048588 -0.865286842936\n-0.756802495308 -0.653643620864\n-0.929014501271 -0.370043316963\n-0.998954917098 -0.0457063847386\n-0.958924274663 0.283662185463\n-0.813329391568 0.581803489859\n-0.578198241744 0.815896312802\n-0.279415498199 0.96017028665\n0.0501270098822 0.998742851229\n'
 404 
 405 In [7]: lines.split()
 406 Out[7]: 
 407 ['0.0',
 408  '1.0',
 409  '0.327194696796',
 410  '0.944956946315',
 411  '0.61836980307',
 412  '0.785887260777',
 413  '0.841470984808',
 414  '0.540302305868',
 415  '0.971937901363',
 416  '0.235237573303',
 417  '0.995407957752',
 418  '-0.0957235480144',
 419  '0.909297426826',
 420  '-0.416146836547',
 421  '0.723085881738',
 422  '-0.69075813975',
 423  '0.457272626636',
 424  '-0.889326568213',
 425  '0.14112000806',
 426  '-0.9899924966',
 427  '-0.190567962875',
 428  '-0.981674004711',
 429  '-0.501277048588',
 430  '-0.865286842936',
 431  '-0.756802495308',
 432  '-0.653643620864',
 433  '-0.929014501271',
 434  '-0.370043316963',
 435  '-0.998954917098',
 436  '-0.0457063847386',
 437  '-0.958924274663',
 438  '0.283662185463',
 439  '-0.813329391568',
 440  '0.581803489859',
 441  '-0.578198241744',
 442  '0.815896312802',
 443  '-0.279415498199',
 444  '0.96017028665',
 445  '0.0501270098822',
 446  '0.998742851229']
 447 
 448 In [8]: 
 449 
 450 In [8]: 
 451 Do you really want to exit ([y]/n)? 
 452 odd% ipython
 453 Python 2.7.6 (default, Sep  9 2014, 15:04:36) 
 454 Type "copyright", "credits" or "license" for more information.
 455 
 456 IPython 2.0.0 -- An enhanced Interactive Python.
 457 ?         -> Introduction and overview of IPython's features.
 458 %quickref -> Quick reference.
 459 help      -> Python's own help system.
 460 object?   -> Details about 'object', use 'object??' for extra details.
 461 
 462 In [1]: lines=file("test.txt","r").readlines()
 463 
 464 In [2]: values=[]
 465 
 466 In [3]: for l in lines:
 467    ...:     v=l.split()
 468    ...:     values.append((float(v[0]),float(v[1])))
 469    ...:     
 470 
 471 In [4]: values
 472 Out[4]: 
 473 [(0.0, 1.0),
 474  (0.327194696796, 0.944956946315),
 475  (0.61836980307, 0.785887260777),
 476  (0.841470984808, 0.540302305868),
 477  (0.971937901363, 0.235237573303),
 478  (0.995407957752, -0.0957235480144),
 479  (0.909297426826, -0.416146836547),
 480  (0.723085881738, -0.69075813975),
 481  (0.457272626636, -0.889326568213),
 482  (0.14112000806, -0.9899924966),
 483  (-0.190567962875, -0.981674004711),
 484  (-0.501277048588, -0.865286842936),
 485  (-0.756802495308, -0.653643620864),
 486  (-0.929014501271, -0.370043316963),
 487  (-0.998954917098, -0.0457063847386),
 488  (-0.958924274663, 0.283662185463),
 489  (-0.813329391568, 0.581803489859),
 490  (-0.578198241744, 0.815896312802),
 491  (-0.279415498199, 0.96017028665),
 492  (0.0501270098822, 0.998742851229)]
 493 
 494 In [5]: values[5]
 495 Out[5]: (0.995407957752, -0.0957235480144)
 496 
 497 In [6]: for v in values: print v
 498 (0.0, 1.0)
 499 (0.327194696796, 0.944956946315)
 500 (0.61836980307, 0.785887260777)
 501 (0.841470984808, 0.540302305868)
 502 (0.971937901363, 0.235237573303)
 503 (0.995407957752, -0.0957235480144)
 504 (0.909297426826, -0.416146836547)
 505 (0.723085881738, -0.69075813975)
 506 (0.457272626636, -0.889326568213)
 507 (0.14112000806, -0.9899924966)
 508 (-0.190567962875, -0.981674004711)
 509 (-0.501277048588, -0.865286842936)
 510 (-0.756802495308, -0.653643620864)
 511 (-0.929014501271, -0.370043316963)
 512 (-0.998954917098, -0.0457063847386)
 513 (-0.958924274663, 0.283662185463)
 514 (-0.813329391568, 0.581803489859)
 515 (-0.578198241744, 0.815896312802)
 516 (-0.279415498199, 0.96017028665)
 517 (0.0501270098822, 0.998742851229)
 518 
 519 In [7]: for x,y in values: print x
 520 0.0
 521 0.327194696796
 522 0.61836980307
 523 0.841470984808
 524 0.971937901363
 525 0.995407957752
 526 0.909297426826
 527 0.723085881738
 528 0.457272626636
 529 0.14112000806
 530 -0.190567962875
 531 -0.501277048588
 532 -0.756802495308
 533 -0.929014501271
 534 -0.998954917098
 535 -0.958924274663
 536 -0.813329391568
 537 -0.578198241744
 538 -0.279415498199
 539 0.0501270098822
 540 
 541 In [8]: for x,y in values: print y
 542 1.0
 543 0.944956946315
 544 0.785887260777
 545 0.540302305868
 546 0.235237573303
 547 -0.0957235480144
 548 -0.416146836547
 549 -0.69075813975
 550 -0.889326568213
 551 -0.9899924966
 552 -0.981674004711
 553 -0.865286842936
 554 -0.653643620864
 555 -0.370043316963
 556 -0.0457063847386
 557 0.283662185463
 558 0.581803489859
 559 0.815896312802
 560 0.96017028665
 561 0.998742851229
 562 
 563 In [9]: for x,y,z in values: print y
 564 ---------------------------------------------------------------------------
 565 ValueError                                Traceback (most recent call last)
 566 <ipython-input-9-51a65087b71e> in <module>()
 567 ----> 1 for x,y,z in values: print y
 568 
 569 ValueError: need more than 2 values to unpack
 570 
 571 In [10]: q=[(1,2),(1,3),(1,4)]
 572 
 573 In [11]: q
 574 Out[11]: [(1, 2), (1, 3), (1, 4)]
 575 
 576 In [12]: zip(*q)
 577 Out[12]: [(1, 1, 1), (2, 3, 4)]
 578 
 579 In [13]: zip([(1,2,3),(1,3,5),(1,4,7),(2,5,8)])
 580 Out[13]: [((1, 2, 3),), ((1, 3, 5),), ((1, 4, 7),), ((2, 5, 8),)]
 581 
 582 In [14]: zip((1,2,3),(1,3,5),(1,4,7),(2,5,8))
 583 Out[14]: [(1, 1, 1, 2), (2, 3, 4, 5), (3, 5, 7, 8)]
 584 
 585 In [15]: a=10000.0
 586 
 587 In [16]: b=0
 588 
 589 In [17]: for i in xrange(10000): b+=1
 590 
 591 In [18]: a==b
 592 Out[18]: True
 593 
 594 In [19]: b
 595 Out[19]: 10000
 596 
 597 In [20]: a=10000.0
 598 
 599 In [21]: b=0
 600 
 601 In [22]: for i in xrange(80000): b+=0.125
 602 
 603 In [23]: a==b
 604 Out[23]: True
 605 
 606 In [24]: b
 607 Out[24]: 10000.0
 608 
 609 In [25]: a=10000.0
 610 
 611 In [26]: b=0
 612 
 613 In [27]: for i in xrange(100000): b+=0.1
 614 
 615 In [28]: a==b
 616 Out[28]: False
 617 
 618 In [29]: a
 619 Out[29]: 10000.0
 620 
 621 In [30]: b
 622 Out[30]: 10000.000000018848
 623 
 624 In [31]: from decimal import Decimal
 625 
 626 In [32]: Decimal(10.1)
 627 Out[32]: Decimal('10.0999999999999996447286321199499070644378662109375')
 628 
 629 In [33]: Decimal("10.1")
 630 Out[33]: Decimal('10.1')
 631 
 632 In [34]: from fractions import Fraction
 633 
 634 In [35]: Fraction(3,5)
 635 Out[35]: Fraction(3, 5)
 636 
 637 In [36]: Fraction(3,5)*Fraction(10,2)
 638 Out[36]: Fraction(3, 1)
 639 
 640 In [37]: Fraction(Decimal("10.1"))
 641 Out[37]: Fraction(101, 10)
 642 
 643 In [38]: Fraction(10.1)
 644 Out[38]: Fraction(5685794529555251, 562949953421312)
 645 
 646 In [39]: help(Fraction)
 647 
 648 
 649 In [40]: from math import *
 650 
 651 In [41]: 
 652 
 653 In [41]: x=[i/1000000.0 for i in xrange(10000000)]
 654 
 655 In [42]: y=[sin(i) for i in x]
 656 
 657 In [43]: len(x)
 658 Out[43]: 10000000
 659 
 660 In [44]: from numpy import *
 661 
 662 In [45]: 
 663 
 664 In [45]: x=arange(0,10.0,0.000001)
 665 
 666 In [46]: y=sin(x)
 667 
 668 In [47]: len(x)
 669 Out[47]: 10000000
 670 
 671 In [48]: type(x_
 672    ....: 
 673 KeyboardInterrupt
 674 
 675 In [48]: type(x)
 676 Out[48]: numpy.ndarray
 677 
 678 In [49]: array
 679 Out[49]: <function numpy.core.multiarray.array>
 680 
 681 In [50]: a=arange(60)
 682 
 683 In [51]: a
 684 Out[51]: 
 685 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
 686        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
 687        34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
 688        51, 52, 53, 54, 55, 56, 57, 58, 59])
 689 
 690 In [52]: arange(0,1,.1)
 691 Out[52]: array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9])
 692 
 693 In [53]: a=arange(60)
 694 
 695 In [54]: a
 696 Out[54]: 
 697 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
 698        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
 699        34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
 700        51, 52, 53, 54, 55, 56, 57, 58, 59])
 701 
 702 In [55]: a.reshape(6,10)
 703 Out[55]: 
 704 array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
 705        [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
 706        [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
 707        [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
 708        [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
 709        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]])
 710 
 711 In [56]: a.reshape(10,6)
 712 Out[56]: 
 713 array([[ 0,  1,  2,  3,  4,  5],
 714        [ 6,  7,  8,  9, 10, 11],
 715        [12, 13, 14, 15, 16, 17],
 716        [18, 19, 20, 21, 22, 23],
 717        [24, 25, 26, 27, 28, 29],
 718        [30, 31, 32, 33, 34, 35],
 719        [36, 37, 38, 39, 40, 41],
 720        [42, 43, 44, 45, 46, 47],
 721        [48, 49, 50, 51, 52, 53],
 722        [54, 55, 56, 57, 58, 59]])
 723 
 724 In [57]: a.reshape(10,8)
 725 ---------------------------------------------------------------------------
 726 ValueError                                Traceback (most recent call last)
 727 <ipython-input-57-1c32909cbd3f> in <module>()
 728 ----> 1 a.reshape(10,8)
 729 
 730 ValueError: total size of new array must be unchanged
 731 
 732 In [58]: a
 733 Out[58]: 
 734 array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
 735        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
 736        34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
 737        51, 52, 53, 54, 55, 56, 57, 58, 59])
 738 
 739 In [59]: b=a.reshape(6,10)
 740 
 741 In [60]: b
 742 Out[60]: 
 743 array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9],
 744        [10, 11, 12, 13, 14, 15, 16, 17, 18, 19],
 745        [20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
 746        [30, 31, 32, 33, 34, 35, 36, 37, 38, 39],
 747        [40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
 748        [50, 51, 52, 53, 54, 55, 56, 57, 58, 59]])
 749 
 750 In [61]: b.shape
 751 Out[61]: (6, 10)
 752 
 753 In [62]: c=a.reshape(6,5,2)
 754 
 755 In [63]: c
 756 Out[63]: 
 757 array([[[ 0,  1],
 758         [ 2,  3],
 759         [ 4,  5],
 760         [ 6,  7],
 761         [ 8,  9]],
 762 
 763        [[10, 11],
 764         [12, 13],
 765         [14, 15],
 766         [16, 17],
 767         [18, 19]],
 768 
 769        [[20, 21],
 770         [22, 23],
 771         [24, 25],
 772         [26, 27],
 773         [28, 29]],
 774 
 775        [[30, 31],
 776         [32, 33],
 777         [34, 35],
 778         [36, 37],
 779         [38, 39]],
 780 
 781        [[40, 41],
 782         [42, 43],
 783         [44, 45],
 784         [46, 47],
 785         [48, 49]],
 786 
 787        [[50, 51],
 788         [52, 53],
 789         [54, 55],
 790         [56, 57],
 791         [58, 59]]])
 792 
 793 In [64]: a.size
 794 Out[64]: 60
 795 
 796 In [65]: b.size
 797 Out[65]: 60
 798 
 799 In [66]: b.shape
 800 Out[66]: (6, 10)
 801 
 802 In [67]: c.shape
 803 Out[67]: (6, 5, 2)
 804 
 805 In [68]: c.ndim
 806 Out[68]: 3
 807 
 808 In [69]: c.dtype
 809 Out[69]: dtype('int64')
 810 
 811 In [70]: a=arange(0,6.4,.1)
 812 
 813 In [71]: a
 814 Out[71]: 
 815 array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ,
 816         1.1,  1.2,  1.3,  1.4,  1.5,  1.6,  1.7,  1.8,  1.9,  2. ,  2.1,
 817         2.2,  2.3,  2.4,  2.5,  2.6,  2.7,  2.8,  2.9,  3. ,  3.1,  3.2,
 818         3.3,  3.4,  3.5,  3.6,  3.7,  3.8,  3.9,  4. ,  4.1,  4.2,  4.3,
 819         4.4,  4.5,  4.6,  4.7,  4.8,  4.9,  5. ,  5.1,  5.2,  5.3,  5.4,
 820         5.5,  5.6,  5.7,  5.8,  5.9,  6. ,  6.1,  6.2,  6.3])
 821 
 822 In [72]: a.dtype
 823 Out[72]: dtype('float64')
 824 
 825 In [73]: a
 826 Out[73]: 
 827 array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ,
 828         1.1,  1.2,  1.3,  1.4,  1.5,  1.6,  1.7,  1.8,  1.9,  2. ,  2.1,
 829         2.2,  2.3,  2.4,  2.5,  2.6,  2.7,  2.8,  2.9,  3. ,  3.1,  3.2,
 830         3.3,  3.4,  3.5,  3.6,  3.7,  3.8,  3.9,  4. ,  4.1,  4.2,  4.3,
 831         4.4,  4.5,  4.6,  4.7,  4.8,  4.9,  5. ,  5.1,  5.2,  5.3,  5.4,
 832         5.5,  5.6,  5.7,  5.8,  5.9,  6. ,  6.1,  6.2,  6.3])
 833 
 834 In [74]: a.dtype
 835 Out[74]: dtype('float64')
 836 
 837 In [75]: b=a.astype("float32")
 838 
 839 In [76]: b
 840 Out[76]: 
 841 array([ 0.        ,  0.1       ,  0.2       ,  0.30000001,  0.40000001,
 842         0.5       ,  0.60000002,  0.69999999,  0.80000001,  0.89999998,
 843         1.        ,  1.10000002,  1.20000005,  1.29999995,  1.39999998,
 844         1.5       ,  1.60000002,  1.70000005,  1.79999995,  1.89999998,
 845         2.        ,  2.0999999 ,  2.20000005,  2.29999995,  2.4000001 ,
 846         2.5       ,  2.5999999 ,  2.70000005,  2.79999995,  2.9000001 ,
 847         3.        ,  3.0999999 ,  3.20000005,  3.29999995,  3.4000001 ,
 848         3.5       ,  3.5999999 ,  3.70000005,  3.79999995,  3.9000001 ,
 849         4.        ,  4.0999999 ,  4.19999981,  4.30000019,  4.4000001 ,
 850         4.5       ,  4.5999999 ,  4.69999981,  4.80000019,  4.9000001 ,
 851         5.        ,  5.0999999 ,  5.19999981,  5.30000019,  5.4000001 ,
 852         5.5       ,  5.5999999 ,  5.69999981,  5.80000019,  5.9000001 ,
 853         6.        ,  6.0999999 ,  6.19999981,  6.30000019], dtype=float32)
 854 
 855 In [77]: b.dtype
 856 Out[77]: dtype('float32')
 857 
 858 In [78]: 
 859 Do you really want to exit ([y]/n)? 
 860 odd% 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.