Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 6,
  6. "metadata": {
  7. "collapsed": false
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import numpy as np"
  12. ]
  13. },
  14. {
  15. "cell_type": "code",
  16. "execution_count": 11,
  17. "metadata": {
  18. "collapsed": false
  19. },
  20. "outputs": [],
  21. "source": [
  22. "a = np.array([\n",
  23. " [\n",
  24. " [6, 7, 8],\n",
  25. " [9, 10, 11],\n",
  26. " ],\n",
  27. " [\n",
  28. " [1, 2, 3],\n",
  29. " [4, 5, 6]\n",
  30. " ],\n",
  31. " [\n",
  32. " [1, 5, 10],\n",
  33. " [23, 12, 11]\n",
  34. " ],\n",
  35. "])\n",
  36. "\n",
  37. "b = np.array([\n",
  38. " [2, 3],\n",
  39. " [4, 5],\n",
  40. " [6, 7],\n",
  41. "])"
  42. ]
  43. },
  44. {
  45. "cell_type": "code",
  46. "execution_count": 12,
  47. "metadata": {
  48. "collapsed": false
  49. },
  50. "outputs": [
  51. {
  52. "name": "stdout",
  53. "output_type": "stream",
  54. "text": [
  55. "[[ 39 44 49]\n",
  56. " [ 24 33 42]\n",
  57. " [167 114 137]]\n"
  58. ]
  59. }
  60. ],
  61. "source": [
  62. "result = []\n",
  63. "for c, d in zip(b, a):\n",
  64. " result.append(c.dot(d))\n",
  65. "result = np.array(result)\n",
  66. "print(result)"
  67. ]
  68. },
  69. {
  70. "cell_type": "code",
  71. "execution_count": 13,
  72. "metadata": {
  73. "collapsed": false
  74. },
  75. "outputs": [
  76. {
  77. "data": {
  78. "text/plain": [
  79. "array([[ 39, 44, 49],\n",
  80. " [ 24, 33, 42],\n",
  81. " [167, 114, 137]])"
  82. ]
  83. },
  84. "execution_count": 13,
  85. "metadata": {},
  86. "output_type": "execute_result"
  87. }
  88. ],
  89. "source": [
  90. "tmp = np.dot(b, a)\n",
  91. "np.diagonal(tmp, axis1=0, axis2=1).T"
  92. ]
  93. },
  94. {
  95. "cell_type": "code",
  96. "execution_count": null,
  97. "metadata": {
  98. "collapsed": true
  99. },
  100. "outputs": [],
  101. "source": []
  102. }
  103. ],
  104. "metadata": {
  105. "kernelspec": {
  106. "display_name": "Python 2",
  107. "language": "python",
  108. "name": "python2"
  109. },
  110. "language_info": {
  111. "codemirror_mode": {
  112. "name": "ipython",
  113. "version": 2
  114. },
  115. "file_extension": ".py",
  116. "mimetype": "text/x-python",
  117. "name": "python",
  118. "nbconvert_exporter": "python",
  119. "pygments_lexer": "ipython2",
  120. "version": "2.7.6"
  121. }
  122. },
  123. "nbformat": 4,
  124. "nbformat_minor": 0
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement