[에러기록] TypeError: Input 'y' of 'Mul' Op has type float64 that does not match type float32 of argument 'x'.

2022. 6. 1. 20:48·프로그래밍 Programming/파이썬 Python

이 오류는 tensorflow에서 tensor 연산을 할 때 나올 수 있는 오류이다.

 

tensorflow는 tensor를 정의할 때 float라고 해도 float32로 설정한다. 즉, 32비트 공간만 쓰겠다는 것이다.

그런데 numpy의 경우에는 float를 float64로 설정한다.

따라서 numpy로 만든 array를 tensor로 만든 다음에 내가 새로 정의한 tensor와 계산을 하려니 오류가 나는 것이었다.

 

해결방법

 

numpy array를 만들 때

array.astype(float32) # array는 배열 이름

이렇게 array의 타입을 바꿔주거나

 

tensor를 정의할 때 type을 float64로 하든, 데이터형을 맞춰주면 된다.

float64가 용량을 더 많이 차지하는 것만 고려하면 될 듯하다.

 

 

참고자료

 

https://stackoverflow.com/questions/36210887/how-to-fix-matmul-op-has-type-float64-that-does-not-match-type-float32-typeerror

 

How to fix MatMul Op has type float64 that does not match type float32 TypeError?

I am trying to save Nueral Network weights into a file and then restoring those weights by initializing the network instead of random initialization. My code works fine with random initialization. ...

stackoverflow.com

 

저작자표시 비영리 변경금지

'프로그래밍 Programming > 파이썬 Python' 카테고리의 다른 글

[에러기록] (pytorch) RuntimeError: Numpy is not available  (0) 2022.07.06
[Python] Visual studio code에서 python 파일(.py) compile하는 방법과 exited with code=9009 에러 해결  (2) 2022.07.05
[Matplotlib] 내가 쓰는 배경이 어두운 색일 때 matplotlib 설정  (0) 2022.04.27
파이썬에 대한 몇 가지 설명  (0) 2021.05.25
[Python] 내가 헷갈려서 기록하는 matplotlib의 subplot 그리기  (0) 2021.04.22
'프로그래밍 Programming/파이썬 Python' 카테고리의 다른 글
  • [에러기록] (pytorch) RuntimeError: Numpy is not available
  • [Python] Visual studio code에서 python 파일(.py) compile하는 방법과 exited with code=9009 에러 해결
  • [Matplotlib] 내가 쓰는 배경이 어두운 색일 때 matplotlib 설정
  • 파이썬에 대한 몇 가지 설명
보통의공대생
보통의공대생
수학,프로그래밍,기계항공우주 등 공부하는 기록들을 남깁니다.
  • 보통의공대생
    뛰는 놈 위에 나는 공대생
    보통의공대생
  • 전체
    오늘
    어제
    • 분류 전체보기 (458)
      • 공지 (1)
      • 영어 공부 English Study (40)
        • 텝스 TEPS (7)
        • 글 Article (21)
        • 영상 Video (10)
      • 연구 Research (99)
        • 최적화 Optimization (3)
        • 데이터과학 Data Science (7)
        • 인공지능 Artificial Intelligent (40)
        • 제어 Control (45)
      • 프로그래밍 Programming (103)
        • 매트랩 MATLAB (25)
        • 파이썬 Python (33)
        • 줄리아 Julia (2)
        • C++ (3)
        • 리눅스 우분투 Ubuntu (6)
      • 항공우주 Aeronautical engineeri.. (21)
        • 항법 Navigation (0)
        • 유도 Guidance (0)
      • 기계공학 Mechanical engineering (13)
        • 열역학 Thermodynamics (0)
        • 고체역학 Statics & Solid mechan.. (10)
        • 동역학 Dynamics (1)
        • 유체역학 Fluid Dynamics (0)
      • 수학 Mathematics (34)
        • 선형대수학 Linear Algebra (18)
        • 미분방정식 Differential Equation (3)
        • 확률및통계 Probability & Sta.. (2)
        • 미적분학 Calculus (1)
        • 복소해석학 Complex Analysis (5)
        • 실해석학 Real Analysis (0)
      • 수치해석 Numerical Analysis (21)
      • 확률 및 랜덤프로세스 Random process (2)
      • 추론 & 추정 이론 Estimation (3)
      • 기타 (26)
        • 설계 프로젝트 System Design (8)
        • 논문작성 Writing (55)
        • 세미나 Seminar (2)
        • 생산성 Productivity (3)
      • 유학 생활 Daily (6)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Zotero
    WOX
    LaTeX
    MATLAB
    논문작성법
    인공지능
    논문작성
    우분투
    텝스
    obsidian
    생산성
    Python
    matplotlib
    ChatGPT
    에러기록
    딥러닝
    고체역학
    수식삽입
    teps
    Numerical Analysis
    Julia
    IEEE
    Statics
    JAX
    옵시디언
    수치해석
    Linear algebra
    pytorch
    텝스공부
    Dear abby
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
보통의공대생
[에러기록] TypeError: Input 'y' of 'Mul' Op has type float64 that does not match type float32 of argument 'x'.
상단으로

티스토리툴바