gpu를 활용해 코드를 작성하던 도중, plot에 cupy로 작성한 배열이 출력되지 않는 오류가 발생했다.

찾아본 결과 cupy 배열은 matplot에 적용이 되지 않는 것이었다.

 

이를 해결하기 위해 cupy를 numpy로 바꾸는 코드를 적용하여 문제를 해결하였다.

https://docs.cupy.dev/en/stable/reference/generated/cupy.asnumpy.html

import cupy as cp
import matplotlib.pyplot as plt

def test_function(x):
    y = x * 10
    return(y)

x = cp.array([0.1, 0.2, 0.3, 0.4, 0.5])
y = test_function(x)
print(y)

plt.plot(cp.asnumpy(y))
plt.show()

 

+ Recent posts