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:07:01 (CDT)
Duration:
0s
Show/Hide answer
{
  "coding": [
    {
      "tag": "bb6c4c69-40fb-4c24-a9cb-6790a49d61b6",
      "uuid": "c4038718-1dbf-4624-b0a5-4ead4a2f0e0a",
      "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": "abee7687-f6a0-4a41-b0d0-4c8024ce34bd",
      "uuid": "fc244759-a8e7-41fe-9067-921de856f140",
      "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": "fe41fd5b-328e-4226-8b5e-06dd9e1a4aa4",
      "uuid": "e79a1ef2-5696-46c8-8bfb-e8a34685a8dd",
      "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": "ef01a30d-5b11-4abe-aaa2-5bf4804c810b",
      "uuid": "cf6f0304-93a3-4195-bb98-94f32f065ff7",
      "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": "dee76cc8-ba1b-46fa-a6c5-cc6ee034d40c",
      "uuid": "ffc4e83f-f01f-4a2e-b1da-6abf3aa7ad50",
      "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": "f28dae21-0360-4177-8cda-144242295e65",
      "uuid": "ecfa8a2b-7c21-4ba3-a71a-e64b33de7420",
      "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": "bcc49bff-75b1-45fd-adc3-5cb1ea11394e",
      "uuid": "a3661532-edc8-4802-a108-4f00d7220fa3",
      "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": "ffd07c7d-e028-4ccd-8504-30650b905814",
      "uuid": "d9c806ab-847e-4057-8e9e-c881a7ee6aac",
      "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