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:08:03 (CDT)
Duration:
0s
Show/Hide answer
{
  "coding": [
    {
      "tag": "ade0af2b-bc1b-49d5-a95f-184e04e2cd0e",
      "uuid": "dc888cf5-003d-4eef-b82c-37986ab68529",
      "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": "f7c4dde1-081d-40aa-83db-3ccda43b230d",
      "uuid": "e0c97d02-6cbf-4492-8955-72795e75fe9b",
      "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": "b9f7a9a6-8a12-4c87-9b39-c6e2427c1eae",
      "uuid": "f55c8202-5d38-4332-ab8f-6c71ce111a8c",
      "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": "e00f1101-dfcf-42d1-ad94-3e8083659095",
      "uuid": "ae24129c-ea59-495a-bdb3-9b0e3f7b6d0e",
      "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": "ede56224-6f56-4f92-8d6d-8ef3ea8aafbd",
      "uuid": "fdedbe71-f9a8-4ad8-998d-998cb2994dc3",
      "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": "c3f8b9b5-d4b5-4f96-91ef-42fbffbd815d",
      "uuid": "d5133164-4844-4e98-b8e1-beda7a82fdef",
      "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": "b59fc321-201c-4894-a1ab-0da0ea8dd275",
      "uuid": "e5952db1-e590-45d4-9bd4-d4660ea01f3a",
      "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": "ae377fa5-079d-4bd9-843e-71ff189399c8",
      "uuid": "f1be485f-2567-4732-9d8f-ad7fa5626dd7",
      "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