0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

keisan3

Posted at
title.rb

import pandas as pd
import numpy as np

# DataFrameの作成
df = pd.DataFrame(columns=['r', 'theta', 'phi'])

# r, theta, phiの値を生成するリスト内包表記
data = [{'r': r, 'theta': theta, 'phi': phi} 
        for r in range(4, 5)  # rの範囲は1~10
        for theta in range(-60, 62, 2)
        for phi in range(-60, 62, 2)]

# DataFrameにデータを追加
df = df.append(data, ignore_index=True)

df['x'] = df['r'] * np.sin(np.radians(df['theta'].astype(float))) * np.cos(np.radians(df['phi'].astype(float)))
df['y'] = -df['r'] * np.sin(np.radians(df['phi'].astype(float))) / np.cos(np.radians(df['theta'].astype(float)))
df['z'] = df['r'] * np.cos(np.radians(df['theta'].astype(float))) * np.cos(np.radians(df['phi'].astype(float)))
df['r_check'] = (df['x']**2 + df['y']**2 + df['z']**2)**0.5

print(df['r_check'].unique())
# データフレームを表示
df.tail()



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?