Python for Cognitive Science#

Joining the workshop?

Complete the setup guide on your own laptop before Day 1.

Two Python days. One shared foundation.

Refresh the Python you already know and make it reliable enough for cognitive neuroscience, natural language processing, and data science.

This is an interactive workshop for incoming MSc Cognitive Science students at Aarhus University. The first two days revisit Python for three courses on the programme:

  • Advanced Cognitive Neuroscience

  • Natural Language Processing

  • Data Science, Prediction and Forecasting

The courses use Python for different scientific purposes, but they rely on the same fundamentals: values and types, collections, control flow, functions, objects, files, arrays, tables, visualisation, and reproducible environments. This workshop revisits that shared foundation before connecting it to course-specific examples.

Day 3 is an open conversation about learning, expectations for the Master’s degree, and the courses ahead. We will talk about what students want to learn, which skills they want to build, and how they want to approach the start of the programme. It is not a coding notebook day.

It is not designed as a first introduction to programming. The aim is to make familiar ideas available again, fill in gaps, and build dependable habits for reading and debugging research code. See Python across the MSc courses for a map of what each course is likely to require.

What you will be able to do#

By the end of the workshop, you can:

  • create a reproducible Python environment in VS Code;

  • navigate research projects safely with pathlib;

  • understand objects, methods, attributes, and dictionaries;

  • reason about NumPy shapes, dimensions, and axes;

  • turn 3D epochs into an evoked response;

  • make clear figures with Matplotlib;

  • clean and summarise experimental data with pandas;

  • recognise the shared fit/predict workflow of data-science models;

  • work effectively with the data structures used in NLP;

  • diagnose common errors before asking for help.

How the workshop works#

Each block follows the same rhythm:

  1. Predict before running the code.

  2. Discuss plausible answers as a group.

  3. Run and inspect the result.

  4. Explain what Python did and why.

  5. Vary the example independently.

The notebooks are where you write, run, debug, and vary the code yourself.

Two people discuss how learning Python apparently lets one of them fly by importing antigravity.

Fig. 1 Python can feel a little like this, although most workshop exercises obey gravity. “Python” by Randall Munroe, licensed CC BY-NC 2.5.#

The workshop principle

Knowing syntax is not the same as having a dependable mental model. We care about what your objects contain, which dimensions your arrays have, and what each transformation means scientifically.

Start with Setup before the workshop, then keep Workshop cheatsheet open during the exercises.

A note on Python documentation#

This book contains explanations and worked examples, but no workshop can document every library function. An important learning goal is therefore knowing how to investigate an unfamiliar object. The chapter Reading Python documentation shows how to use help(), docstrings, signatures, official API references, and small experiments.