You are viewing this question as it will appear in the manual grading interface. Return to the normal view when you are done.

Element pl-order-blocks: Externally graded python code using numpy

We want to run the following code snippet, where we randomly define two 1d numpy arrays, and call a function that computes the dot product between these two arrays:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import numpy as np

a = np.random.rand(4)
b = np.random.rand(4)

print("# Given two 1d numpy arrays:")
print(a)
print(b)
print("# Your function returns:")
print( my_dot_product(a,b) )

Write the function my_dot_product:

Drag from here:
  • 1
    d = a*b
    
  • 1
    d = a.T@b
    
  • 1
    d = a@b
    
  • 1
    d = np.inner(a,b)
    
  • 1
    d = np.outer(a,b)
    
  • 1
    def my_dot_product(a,b):
    
  • 1
    return 
    
  • 1
    return d
    
Construct your solution here:

Correct answer

Student view placeholder

In student views this area is used for assessment and score info.
Tools

Staff information

Question

Title:
Element pl-order-blocks: Externally graded python code using numpy

Variant

Started at:
2026-09-19 07:55:38 (CDT)
Duration:
0s
Show/Hide answer
{
  "coding": [
    {
      "tag": "efda7f15-2b18-4b50-8e6e-2691b2671dab",
      "uuid": "f00e7687-b01d-4117-8440-b5886b52ad07",
      "final": false,
      "index": 0,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">def my_dot_product(a,b):</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "d8ff7645-3120-48c9-9d38-aa1a220cef74",
      "uuid": "d106cbda-adaa-42af-9793-c3367e4ab969",
      "final": false,
      "index": 1,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">return d</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "e1ab7717-0ca2-4c66-9481-9464a9cfd05f",
      "uuid": "a2a5b5bc-f798-4315-b8ad-bc7f1152855a",
      "final": false,
      "index": 2,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">return </pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "b37d5d9e-4bf0-470a-91f2-5fded30b7ee4",
      "uuid": "cc357f19-86a6-4e79-aecd-870f17d0f728",
      "final": false,
      "index": 3,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">d = a*b</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "d7ad92e7-32dd-4337-adfb-269c24cc8b45",
      "uuid": "a3aa7a92-e6a8-44d5-a65f-18f41eab0d59",
      "final": false,
      "index": 4,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">d = a@b</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "a64dccda-e3a2-4c08-b33f-0336d9f10fb5",
      "uuid": "fbfa6023-5679-4340-9eca-0bc105bfca18",
      "final": false,
      "index": 5,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">d = a.T@b</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "c56b0c70-a232-4d55-8c91-e8e90632b55c",
      "uuid": "ee74a5e6-a4ca-4fdc-85c6-1adac35d884f",
      "final": false,
      "index": 6,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">d = np.inner(a,b)</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    },
    {
      "tag": "ebc48904-60d9-4b57-92f9-3869dbb60190",
      "uuid": "ca8afbc7-b347-4e6f-afd9-9e30bedf736b",
      "final": false,
      "index": 7,
      "indent": -1,
      "depends": [],
      "ranking": -1,
      "group_info": {
        "tag": null,
        "depends": null
      },
      "inner_html": "<pl-code language=\"python\">d = np.outer(a,b)</pl-code>",
      "distractor_for": null,
      "initially_placed": false,
      "ordering_feedback": null,
      "distractor_feedback": null
    }
  ]
}
History
dec frac
rad deg