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 10:15:04 (CDT)
Duration:
0s
Show/Hide answer
{
  "coding": [
    {
      "tag": "e9a1a204-4714-4e43-916c-f155ce044f59",
      "uuid": "f9ea6f7d-9482-4abf-a857-bc760aba3ba1",
      "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": "d8fb28db-3958-4d29-bc5a-5d3957f35e47",
      "uuid": "dbd92c71-74b1-4702-9018-11d1c5497bb0",
      "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": "e969c26f-9c6b-490f-b35e-e926ca452feb",
      "uuid": "a1670792-8974-42bc-b20c-3b043caf14c9",
      "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": "bbbccd80-d7ac-4a76-a9fc-234be5aa9a2c",
      "uuid": "c92ccc57-8c67-4ad1-847f-c9f8b8d255ac",
      "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": "dc539c21-f1dc-4d85-9327-39711830aef7",
      "uuid": "ad9640f6-2bdf-4dea-9c3d-9ae10bf93787",
      "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": "ad11f992-66bd-4ae2-afa3-4699e7254cb2",
      "uuid": "f2bc301f-be6d-4643-a560-0fc8162f5a89",
      "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": "c5e5fe80-5e55-4d1a-834f-8f965dcab617",
      "uuid": "e2c8d086-d0fa-40db-b332-78470bdf44ba",
      "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": "e1d52195-159f-442f-ac4d-f311c74b4a26",
      "uuid": "c73b7b4f-fa4e-4c3f-98c4-427f1ac43470",
      "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