Guest User

Untitled

a guest
Jan 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. a = np.array([3.4, 5])
  2. res = np.exp(a, a)
  3. print(res is a)
  4. print(a)
  5.  
  6. True
  7. [ 29.96410005 148.4131591 ]
  8.  
  9. In [12]: b
  10. Out[12]: array([1, 2, 3, 4, 5], dtype=int32)
  11.  
  12. In [13]: np.exp(b, b)
  13. --------------------------------------------------------------------------
  14. TypeError: ufunc 'exp' output (typecode 'd') could not be coerced to provided
  15. output parameter (typecode 'i') according to the casting rule ''same_kind''
  16.  
  17. # in-place typecasting
  18. In [14]: b = b.astype(np.float64, copy=False)
  19. In [15]: b
  20. Out[15]: array([ 1., 2., 3., 4., 5.], dtype=float64)
  21.  
  22. # modifies b in-place
  23. In [16]: np.exp(b, b)
  24. Out[16]: array([ 2.718, 7.389, 20.086, 54.598, 148.413], dtype=float64)
Add Comment
Please, Sign In to add comment