> For the complete documentation index, see [llms.txt](https://tobigs.gitbook.io/tobigs-graph-study/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tobigs.gitbook.io/tobigs-graph-study/chapter2./python-code-kronecker-product.md).

# Python code - kronecker product

## Kronecker product - numpy

{% embed url="<https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.kron.html>" %}

`numpy.kron`(*a*, *b*)[\[source\]](http://github.com/numpy/numpy/blob/v1.13.0/numpy/lib/shape_base.py#L727-L823)

a, b에는 kronecker product를 구하고자 하는 행렬이 각각 파라미터로 들어가고, kronecker product의 결과값을 리턴합니다.&#x20;

## Kronecker product MLE 구현하기

```python
import numpy as np
G = [[1,0,1,1],[0,1,0,1],[1,0,1,1],[1,1,1,1]]
KM = [[0.5,0.2],[0.1,0.3]]
KM = np.kron(KM, KM)
P = 1
for i in range(KM.shape[0]):
  for j in range(KM.shape[1]):
    # G에 속할 때.
    if G[i][j]==1:
      P = P*KM[i][j]
    # G에 속하지 않을 때.
    else:
      P = P*(1-KM[i][j])
# P는 kronecker 로부터 생성된 그래프가 실제 G일 확률을 나타냄.
print(P)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tobigs.gitbook.io/tobigs-graph-study/chapter2./python-code-kronecker-product.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
