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 09:08:04 (CDT)
Duration:
0s
Show/Hide answer
{
  "coding": [
    {
      "tag": "b64a02e2-03c8-4fea-8983-cb21ae222b71",
      "uuid": "cff1739d-38b0-434b-82d4-883f30c65f3d",
      "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": "a26d95fc-eedd-4cc5-8497-fa1214da2a57",
      "uuid": "fd4bcf82-8c18-48c0-8452-59c4b19ccd70",
      "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": "fa5c624d-4e21-4760-8048-fb21c55da2e4",
      "uuid": "e1a2cda1-d779-44ff-ae69-346e80862a65",
      "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": "e188d3a9-dd63-4971-b065-0bb83e2df2a9",
      "uuid": "c4b80a79-b57b-45e1-ae91-30002211c450",
      "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": "df0272b9-c561-4d5f-93bb-4c9e052ddf53",
      "uuid": "fe670595-a384-4fd3-bd8c-3abf2646fb78",
      "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": "f916654f-410a-4433-9712-876afc040725",
      "uuid": "efe232dd-48a2-4881-a416-e85f3de1c802",
      "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": "beea5ffd-c1db-462c-8848-2b79aeba5810",
      "uuid": "a9a891dd-7e23-4381-9ecd-ac368b7ab690",
      "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": "fde635f3-bdea-427a-b209-54387c725734",
      "uuid": "d26a6fe8-fd0f-4367-b518-241fb02248fa",
      "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