├── notebook ├── data │ ├── temp │ │ └── .gitkeep │ ├── dst │ │ ├── target_2.txt │ │ ├── to_csv_out_header_index.csv │ │ ├── to_csv_out_columns.csv │ │ ├── lena_flip.jpg │ │ ├── lena_q25.jpg │ │ ├── lena_swap.jpg │ │ ├── opencv_th.jpg │ │ ├── qr_lena.png │ │ ├── qr_lena2.png │ │ ├── to_csv_out.csv │ │ ├── to_csv_out.tsv │ │ ├── to_csv_out_nan.csv │ │ ├── horse_flip.png │ │ ├── lena_bgr_cv.jpg │ │ ├── lena_invert.jpg │ │ ├── lena_mirror.jpg │ │ ├── lena_rgb_cv.jpg │ │ ├── lena_swap_2.jpg │ │ ├── mask_circle.jpg │ │ ├── pandas_obj.pkl │ │ ├── pandas_obj.zip │ │ ├── pandas_pie.png │ │ ├── qrcode_test.png │ │ ├── xlwt_sample.xls │ │ ├── barcode_opencv.jpg │ │ ├── color_gradient.jpg │ │ ├── horse_invert.png │ │ ├── horse_mirror.png │ │ ├── lena_bgr_cv_2.jpg │ │ ├── lena_diff_abs.png │ │ ├── lena_diff_bin.png │ │ ├── lena_np_fliplr.jpg │ │ ├── lena_np_flipud.jpg │ │ ├── lena_np_rot90.jpg │ │ ├── lena_rotate_45.jpg │ │ ├── lena_rotate_90.jpg │ │ ├── opencv_affine.jpg │ │ ├── opencv_hconcat.jpg │ │ ├── opencv_th_otsu.jpg │ │ ├── opencv_th_tz.jpg │ │ ├── opencv_vconcat.jpg │ │ ├── opencv_voronoi.png │ │ ├── qrcode_opencv.jpg │ │ ├── qrcode_test2.png │ │ ├── qrcode_test2_2.png │ │ ├── seaborn_iris.png │ │ ├── to_csv_out_nan_rep.csv │ │ ├── candlestick_day.png │ │ ├── candlestick_mpf.png │ │ ├── candlestick_week.png │ │ ├── gray_gradient_h.jpg │ │ ├── gray_gradient_v.jpg │ │ ├── lena_bgr_pillow.jpg │ │ ├── lena_cv_flip_lr.jpg │ │ ├── lena_cv_flip_ud.jpg │ │ ├── lena_diff_center.png │ │ ├── lena_numpy_gamma.jpg │ │ ├── lena_numpy_gray.jpg │ │ ├── lena_numpy_paste.jpg │ │ ├── lena_numpy_roll.jpg │ │ ├── lena_numpy_tile.jpg │ │ ├── lena_numpy_trim.jpg │ │ ├── lena_numpy_trim2.jpg │ │ ├── lena_numpy_trim3.jpg │ │ ├── lena_opencv_gray.jpg │ │ ├── lena_opencv_red.jpg │ │ ├── lena_rgb_pillow.jpg │ │ ├── lena_square_face.jpg │ │ ├── mask_circle_blur.jpg │ │ ├── numpy_gray_calc.jpg │ │ ├── numpy_image_mask.jpg │ │ ├── opencv_delaunay.png │ │ ├── opencv_draw_etc.png │ │ ├── opencv_draw_mask.jpg │ │ ├── opencv_mosaic_01.jpg │ │ ├── openpyxl_sample.xlsx │ │ ├── pandas_iris_area.png │ │ ├── pandas_iris_bar.png │ │ ├── pandas_iris_barh.png │ │ ├── pandas_iris_box.png │ │ ├── pandas_iris_hist.png │ │ ├── pandas_iris_kde.png │ │ ├── pandas_iris_line.png │ │ ├── pandas_to_excel.xlsx │ │ ├── pillow_concat_h.jpg │ │ ├── pillow_concat_v.jpg │ │ ├── pillow_imagedraw.gif │ │ ├── pillow_imagedraw.jpg │ │ ├── skimage_block_00.jpg │ │ ├── skimage_block_01.jpg │ │ ├── skimage_block_10.jpg │ │ ├── skimage_block_11.jpg │ │ ├── to_csv_out_float_default.csv │ │ ├── to_csv_out_float_format_3e.csv │ │ ├── to_csv_out_float_format_3f.csv │ │ ├── candlestick_mpf_mav.png │ │ ├── candlestick_week_v.png │ │ ├── lena_cv_flip_ud_lr.jpg │ │ ├── lena_cv_rotate_180.jpg │ │ ├── lena_diff_abs_norm.png │ │ ├── lena_np_flip_ud_lr.jpg │ │ ├── lena_np_rot90_180.jpg │ │ ├── lena_np_rot90_270.jpg │ │ ├── lena_numpy_inverse.jpg │ │ ├── lena_numpy_split_0.jpg │ │ ├── lena_numpy_split_1.jpg │ │ ├── lena_opencv_red_low.jpg │ │ ├── lena_square_pillow.jpg │ │ ├── mask_circle_blur2.jpg │ │ ├── matplotlib_patches.png │ │ ├── numpy_binarization.png │ │ ├── numpy_image_ab_grad.jpg │ │ ├── numpy_image_mask_l.jpg │ │ ├── opencv_add_weighted.jpg │ │ ├── opencv_affine_flags.jpg │ │ ├── opencv_affine_half.jpg │ │ ├── opencv_affine_mark.jpg │ │ ├── opencv_bitwise_and.jpg │ │ ├── opencv_concat_tile.jpg │ │ ├── opencv_gray_cvtcolr.jpg │ │ ├── opencv_gray_imread.jpg │ │ ├── opencv_hconcat_np.jpg │ │ ├── opencv_mosaic_005.jpg │ │ ├── opencv_mosaic_area.jpg │ │ ├── opencv_mosaic_face.jpg │ │ ├── opencv_random_pts.png │ │ ├── opencv_vconcat_np.jpg │ │ ├── opencv_voronoi_fill.png │ │ ├── pandas_iris_hexbin.png │ │ ├── pandas_iris_line_x.png │ │ ├── pandas_iris_line_xy.png │ │ ├── pandas_iris_line_y.png │ │ ├── pandas_iris_scatter.png │ │ ├── pandas_iris_stacked.png │ │ ├── pandas_obj.csv │ │ ├── pandas_pie_single.png │ │ ├── pillow_concat_h_cut.jpg │ │ ├── pillow_concat_v_cut.jpg │ │ ├── pillow_iamge_draw.jpg │ │ ├── pillow_imagedraw2.jpg │ │ ├── pillow_imagedraw3.jpg │ │ ├── rocket_pillow_paste.jpg │ │ ├── seaborn_heatmap_big.png │ │ ├── seaborn_heatmap_hot.png │ │ ├── sklearn_roc_curve.png │ │ ├── astronaut_add_margin.jpg │ │ ├── astronaut_pillow_crop.jpg │ │ ├── barcode_qrcode_opencv.jpg │ │ ├── barcode_qrcode_pillow.jpg │ │ ├── candlestick_mpf_week.png │ │ ├── candlestick_week_sma.png │ │ ├── lena_diff_center_norm.png │ │ ├── lena_numpy_dec_color.png │ │ ├── lena_numpy_paste_all.jpg │ │ ├── lena_numpy_swap_color.jpg │ │ ├── lena_opencv_red_high.jpg │ │ ├── lena_rotate_45_expand.jpg │ │ ├── lena_rotate_90_expand.jpg │ │ ├── matplotlib_style_test.png │ │ ├── opencv_affine_skew_x.jpg │ │ ├── opencv_affine_skew_y.jpg │ │ ├── opencv_concat_tile_np.jpg │ │ ├── opencv_delaunay_inner.png │ │ ├── opencv_draw_argument.png │ │ ├── opencv_draw_mask_blur.jpg │ │ ├── opencv_hconcat_resize.jpg │ │ ├── opencv_vconcat_resize.jpg │ │ ├── opencv_warp_dst_mark.jpg │ │ ├── opencv_warp_rectangle.jpg │ │ ├── opencv_warp_src_mark.jpg │ │ ├── opencv_warp_triangle.jpg │ │ ├── pandas_datareader_wb.png │ │ ├── pandas_iris_bar_stack.png │ │ ├── pandas_iris_line_axes.png │ │ ├── pandas_iris_line_dpi.png │ │ ├── pandas_iris_line_etc.png │ │ ├── pillow_concat_h_blank.jpg │ │ ├── pillow_concat_v_blank.jpg │ │ ├── pillow_imagedraw_lena.jpg │ │ ├── pillow_imagedraw_text.jpg │ │ ├── pillow_putalpha_horse.png │ │ ├── pillow_putalpha_solid.png │ │ ├── seaborn_heatmap_annot.png │ │ ├── seaborn_heatmap_big_2.png │ │ ├── seaborn_heatmap_blues.png │ │ ├── seaborn_heatmap_list.png │ │ ├── seaborn_pairplot_hue.png │ │ ├── seaborn_pairplot_kws.png │ │ ├── seaborn_pairplot_size.png │ │ ├── seaborn_pairplot_vars.png │ │ ├── skimage_block_change.jpg │ │ ├── skimage_montage_fill.jpg │ │ ├── sklearn_roc_curve_all.png │ │ ├── astronaut_expand_square.jpg │ │ ├── candlestick_day_format.png │ │ ├── candlestick_mpf_candle.png │ │ ├── candlestick_mpf_figratio.png │ │ ├── candlestick_mpf_volume.png │ │ ├── candlestick_week_sma_v.png │ │ ├── iris_pandas_groupby_max.jpg │ │ ├── lena_numpy_binarization.png │ │ ├── lena_numpy_split_color.jpg │ │ ├── lena_opencv_face_detect.jpg │ │ ├── lena_pillow_resize_half.jpg │ │ ├── lena_rotate_0_translate.jpg │ │ ├── lena_rotate_45_bicubic.jpg │ │ ├── lena_rotate_45_translate.jpg │ │ ├── lena_square_pillow_crop.jpg │ │ ├── matplotlib_example_multi.png │ │ ├── matplotlib_seaborn_paper.png │ │ ├── matplotlib_seaborn_ticks.png │ │ ├── matplotlib_style_classic.png │ │ ├── matplotlib_style_default.png │ │ ├── matplotlib_style_ggplot.png │ │ ├── numpy_binarization_color.png │ │ ├── numpy_binarization_keep.png │ │ ├── numpy_image_ab_mask_grad.jpg │ │ ├── numpy_image_alpha_blend.jpg │ │ ├── opencv_affine_mark_dst.jpg │ │ ├── opencv_affine_mark_src.jpg │ │ ├── opencv_delaunay_voronoi.png │ │ ├── opencv_face_detect_fill.jpg │ │ ├── opencv_perspective_dst.jpg │ │ ├── opencv_warp_affine_crop.jpg │ │ ├── opencv_warp_dst_result.jpg │ │ ├── pandas_datareader_stock.png │ │ ├── pandas_datareader_yahoo.png │ │ ├── pandas_iris_hist_alpha.png │ │ ├── pandas_iris_hist_h_step.png │ │ ├── pandas_iris_line_figsize.png │ │ ├── pandas_iris_line_multi.png │ │ ├── pandas_iris_line_style.png │ │ ├── pandas_iris_scatter_line.png │ │ ├── pandas_to_excel_multi.xlsx │ │ ├── pillow_composite_circle.jpg │ │ ├── pillow_composite_horse.jpg │ │ ├── pillow_composite_solid.jpg │ │ ├── pillow_concat_h_resize.jpg │ │ ├── pillow_concat_v_resize.jpg │ │ ├── pillow_imagedraw_text_ja.jpg │ │ ├── pillow_putalpha_circle.png │ │ ├── rocket_pillow_paste_out.jpg │ │ ├── rocket_pillow_paste_pos.jpg │ │ ├── scipy_matplotlib_voronoi.png │ │ ├── seaborn_heatmap_blues_r.png │ │ ├── seaborn_heatmap_list_sub.png │ │ ├── seaborn_heatmap_ndarray.png │ │ ├── seaborn_heatmap_no_cbar.png │ │ ├── seaborn_heatmap_square.png │ │ ├── seaborn_pairplot_default.png │ │ ├── seaborn_pairplot_markers.png │ │ ├── seaborn_pairplot_palette.png │ │ ├── seaborn_pairplot_xy_vars.png │ │ ├── skimage_montage_1_3_pad.jpg │ │ ├── skimage_montage_default.jpg │ │ ├── sklearn_confusion_matrix.png │ │ ├── sklearn_roc_curve_random.png │ │ ├── sklearn_roc_curve_same.png │ │ ├── to_csv_out_float_format_str.csv │ │ ├── astronaut_thumbnail_expand.jpg │ │ ├── lena_pillow_resize_lanczos.jpg │ │ ├── lena_pillow_resize_nearest.jpg │ │ ├── matplotlib_example_single.png │ │ ├── matplotlib_histogram_multi.png │ │ ├── matplotlib_mplot3d_scatter.png │ │ ├── matplotlib_mplot3d_surface.png │ │ ├── matplotlib_seaborn_default.png │ │ ├── matplotlib_seaborn_poster.png │ │ ├── matplotlib_seaborn_set_all.png │ │ ├── matplotlib_seaborn_winter.png │ │ ├── numpy_binarization_color2.png │ │ ├── opencv_add_weighted_gamma.jpg │ │ ├── opencv_affine_border_value.jpg │ │ ├── opencv_affine_border_wrap.jpg │ │ ├── opencv_affine_translation.jpg │ │ ├── opencv_concat_tile_resize.jpg │ │ ├── opencv_face_detect_mosaic.jpg │ │ ├── opencv_warp_dst_crop_mark.jpg │ │ ├── opencv_warp_src_crop_mark.jpg │ │ ├── pandas_iris_line_subplots.png │ │ ├── pandas_iris_scatter_multi.png │ │ ├── pillow_composite_gradation.jpg │ │ ├── pillow_concat_h_cut_center.jpg │ │ ├── pillow_concat_tile_repeat.jpg │ │ ├── pillow_concat_tile_resize.jpg │ │ ├── pillow_concat_v_cut_center.jpg │ │ ├── scipy_matplotlib_delaunay.png │ │ ├── seaborn_heatmap_dataframe.png │ │ ├── seaborn_pairplot_hue_order.png │ │ ├── seaborn_pairplot_kind_reg.png │ │ ├── sklearn_roc_curve_compare.png │ │ ├── sklearn_roc_curve_perfect.png │ │ ├── astronaut_pillow_crop_center.jpg │ │ ├── astronaut_pillow_crop_outside.jpg │ │ ├── candlestick_mpf_style_yahoo.png │ │ ├── lena_cv_rotate_90_clockwise.jpg │ │ ├── lena_numpy_binarization_color.png │ │ ├── lena_rotate_45_change_center.jpg │ │ ├── lena_rotate_45_expand_bicubic.jpg │ │ ├── matplotlib_histogram_single.png │ │ ├── matplotlib_mplot3d_wireframe.png │ │ ├── matplotlib_seaborn_paper_bold.png │ │ ├── matplotlib_seaborn_whitegrid.png │ │ ├── matplotlib_seaborn_winter_r.png │ │ ├── matplotlib_style_test_ggplot.png │ │ ├── numpy_binarization_from_color.png │ │ ├── numpy_image_alpha_blend_gamma.jpg │ │ ├── opencv_affine_mark_dst_mark.jpg │ │ ├── opencv_draw_mask_blur_result.jpg │ │ ├── opencv_face_detect_rectangle.jpg │ │ ├── opencv_warp_affine_crop_merge.jpg │ │ ├── pandas_datareader_morningstar.png │ │ ├── pillow_composite_circle_blur.jpg │ │ ├── pillow_concat_h_multi_blank.jpg │ │ ├── pillow_concat_h_multi_resize.jpg │ │ ├── pillow_concat_v_multi_resize.jpg │ │ ├── pillow_imagedraw_text_anchor.jpg │ │ ├── pillow_imagedraw_text_arial.jpg │ │ ├── pillow_putalpha_circle_blur.png │ │ ├── scipy_matplotlib_voronoi_fill.png │ │ ├── seaborn_heatmap_corr_example.png │ │ ├── seaborn_heatmap_house_price.png │ │ ├── seaborn_pairplot_kind_reg_kws.png │ │ ├── seaborn_pairplot_palette_dict.png │ │ ├── astronaut_thumbnail_max_square.jpg │ │ ├── lena_numpy_binarization_color2.png │ │ ├── lena_rotate_45_fillcolor_expand.jpg │ │ ├── lena_rotate_45_translate_expand.jpg │ │ ├── lena_square_pillow_crop_center.jpg │ │ ├── lena_square_pillow_crop_outside.jpg │ │ ├── matplotlib_seaborn_winter_desat.png │ │ ├── numpy_binarization_from_color2.png │ │ ├── opencv_affine_border_replicate.jpg │ │ ├── opencv_affine_mark_dst_another.jpg │ │ ├── opencv_perspective_dst_inverse.jpg │ │ ├── pandas_iris_line_subplots_share.png │ │ ├── pillow_imagedraw_text_multiline.jpg │ │ ├── pillow_imagedraw_text_textbbox.jpg │ │ ├── rocket_pillow_paste_mask_circle.jpg │ │ ├── rocket_pillow_paste_mask_horse.jpg │ │ ├── seaborn_pairplot_diag_kind_kde.png │ │ ├── seaborn_pairplot_markers_multi.png │ │ ├── to_csv_out_a_new_column.csv │ │ ├── astronaut_pillow_crop_max_square.jpg │ │ ├── astronaut_thumbnail_center_square.jpg │ │ ├── lena_cv_rotate_90_counterclockwise.jpg │ │ ├── matplotlib_style_dark_background.png │ │ ├── opencv_affine_border_transparent.jpg │ │ ├── pandas_datareader_stock_normalize.png │ │ ├── pandas_iris_line_subplots_layout.png │ │ ├── pandas_to_excel_no_index_header.xlsx │ │ ├── scipy_matplotlib_delaunay_voronoi.png │ │ ├── seaborn_heatmap_vmax_vmin_center.png │ │ ├── lena_rotate_45_change_center_expand.jpg │ │ ├── matplotlib_seaborn_whitegrid_dashed.png │ │ ├── matplotlib_style_change_axes_margin.png │ │ ├── rocket_pillow_paste_mask_circle_blur.jpg │ │ ├── sklearn_confusion_matrix_annot_blues.png │ │ ├── to_csv_out_a.csv │ │ ├── astronaut_thumbnail_mask_circle_solid.jpg │ │ ├── matplotlib_style_ggplot_dark_background.png │ │ ├── pandas_datareader_morningstar_normalize.png │ │ ├── astronaut_thumbnail_mask_circle_transparent.png │ │ └── pandas_read_html_sample.csv │ └── src │ │ ├── sample_quote.csv │ │ ├── target_1.txt │ │ ├── test.txt │ │ ├── sample_linebreak.csv │ │ ├── unicode_escape.txt │ │ ├── sample.csv │ │ ├── sample.txt │ │ ├── sample_nan.csv │ │ ├── sample_double_quotation.csv │ │ ├── test_u.json │ │ ├── sample_space.csv │ │ ├── sample_for_grep.txt │ │ ├── sample_header.csv │ │ ├── sample_header_index_nan.csv │ │ ├── lena.jpg │ │ ├── test.json │ │ ├── horse.png │ │ ├── md │ │ ├── test2.md │ │ ├── sub_dir │ │ │ └── test_sub.md │ │ └── test1.md │ │ ├── qrcode.png │ │ ├── rocket.jpg │ │ ├── sample_header_index.csv │ │ ├── sample_header_index.tsv │ │ ├── barcode.jpg │ │ ├── horse_r.png │ │ ├── lena_q50.jpg │ │ ├── lena_q95.jpg │ │ ├── sample.xlsx │ │ ├── gradation_h.jpg │ │ ├── lena_square.png │ │ ├── pdf │ │ ├── sample1.pdf │ │ ├── sample2.pdf │ │ ├── sample3.pdf │ │ ├── sample1_pass_aes.pdf │ │ └── sample1_pass_rc4.pdf │ │ ├── sample_header_index_dtype.csv │ │ ├── astronaut_rect.bmp │ │ ├── barcode_qrcode.jpg │ │ ├── horse_r_resize.png │ │ ├── rocket_resize.jpg │ │ ├── lena_square_half.png │ │ ├── sample_from_pandas_columns.json │ │ ├── sample_header.csv.zip │ │ ├── lena_square_gray_half.png │ │ ├── sample_header_shift_jis.csv │ │ ├── sample_from_pandas_columns.gz │ │ ├── sample_pandas_normal_nan.csv │ │ ├── test.mplstyle │ │ ├── sample_pandas_normal.csv │ │ ├── sample_datetime_multi.csv │ │ ├── sample_date.csv │ │ ├── sample_date_jp.csv │ │ └── sample_multi.csv ├── my_package │ ├── __init__.py │ ├── sub_package1 │ │ ├── __init__.py │ │ └── sub_mod1.py │ ├── sub_package2 │ │ ├── __init__.py │ │ └── sub_mod2.py │ ├── mod1.py │ ├── main.py │ ├── mod2.py │ └── import_example_inside_bash.sh ├── hello_direct.py ├── sys_exit_stderr.py ├── dir_import_test │ ├── mod1.py │ ├── dir_for_mod │ │ └── mod2.py │ ├── dir │ │ ├── main_absolute.py │ │ ├── main_relative.py │ │ └── main_sys_path_append.py │ ├── main_base.py │ ├── import_example_absolute_bash.sh │ └── import_example_relative_bash.sh ├── pass_if.py ├── print_sys_path.py ├── builtin_functions.py ├── doctest_example_testfile.py ├── hello.py ├── input_usage_script.py ├── add_module_import.py ├── sys_exit.py ├── doctest_text.txt ├── hello_main.py ├── locale_getpreferredencoding.py ├── pass_with_open.py ├── add_module_command.py ├── builtin_types.py ├── math_ulp.py ├── hello_if_name.py ├── standard_library_example.py ├── inf_math.py ├── add_module.py ├── inf_numpy.py ├── sys_exit_systemexit.py ├── third_party_library_example.py ├── while_keyboardinterrupt.py ├── pillow_save_lq_images.py ├── scipy_special_perm.py ├── is_compare.py ├── sympy_from_import.py ├── argparse_type_int.py ├── sklearn_f1_score.py ├── sklearn_recall_score.py ├── sys_exit_if.py ├── argparse_option_bool.py ├── argparse_type_bool.py ├── numpy_linalg_det.py ├── sklearn_accuracy_score.py ├── calendar_weekday.py ├── gcd_lcm.py ├── test_main.py ├── import_example_pep.py ├── sklearn_precision_score.py ├── numpy_image_inverse.py ├── ellipsis_object.py ├── numpy_max.py ├── save_file_at_dir.py ├── str_replace_with_empty.py ├── divmod-test.py ├── doctest_example.py ├── heapq_nlargest_nsmallest.py ├── doctest_example_error.py ├── scipy_special_comb.py ├── add_module_argparse.py ├── re_split.py ├── test_module.py ├── doctest_example_verbose.py ├── name_main_example.py ├── print_list_elements.py ├── time_time_usage.py ├── argparse_type_strtobool.py ├── collections_deque_stack.py ├── format_error.py ├── random_uniform.py ├── requests_url_params.py ├── collections_deque_queue.py ├── positive_negative_zero.py ├── sklearn_load_data_import.py ├── import_example_as.py ├── pass_continue.py ├── math_perm.py ├── numpy_roll_image.py ├── requests_request_header.py ├── doctest_example_without_import.py ├── short_circuit.py ├── platform_python_version.py ├── typing_example.py ├── seaborn_iris.py ├── pass_def_class.py ├── int_bit_count_timeit.py ├── numpy_image_declease_color.py ├── empty_dir.py ├── numpy_tile_image.py ├── pandas_read_clipboard.py ├── random_random.py ├── matplotlib_example_single.py ├── os_remove.py ├── pillow_add_margin.py ├── combinations_count.py ├── opencv_videocapture_camera.py ├── numpy_image_gamma.py ├── numpy_list_to_ndarray.py ├── opencv_videocapture_file.py ├── opencv_videocapture_prop_fps.py ├── re_greedy.py ├── datetime_timezone_str.py ├── opencv_videocapture_play_cam.py ├── import_example_relative.py ├── math_comb.py ├── random_list.py ├── sklearn_fetch_olivetti_faces.py ├── tensorflow_constant.py ├── array_example.py ├── os_getcwd_chdir.py ├── pypdf_split.py ├── pypdf_split_pages.py ├── random_choice.py ├── sys_exit_sh.log ├── builtins_module.py ├── int_truncate.py ├── pillow_expand_to_square.py ├── opencv_bitwise_and.py ├── random_randrange_randint.py ├── arxiv_download.py ├── import_example_relative_other.py ├── numpy_rint.py ├── opencv_psnr.py ├── pandas_to_clipboard.py ├── print_len_eafp.py ├── all_example.py ├── numpy_flip_image.py ├── numpy_rot90_image.py ├── pillow_imagegrab_grabclipboard.py ├── str_re_split.py ├── jupyter_precision.py ├── numpy_broadcast_to.py ├── pillow_image_resize.py ├── urllib_request.py ├── sys_argv_test.py ├── for_enumerate_zip.py ├── import_example.py ├── numpy_lcm.py ├── pypdf_merge_dir.py ├── math_ceil.py ├── numpy_method_chain.py ├── numpy_version.py ├── shutil_rmtree.py ├── str_partition_rpartition.py ├── atcoder-version-check.py ├── math_fabs.py ├── import_example_package_collections.py ├── jupyter_youtube_vimeo.py ├── math_floor.py ├── round_towards_infinity.py ├── list_str_re.py ├── pillow_invert.py ├── pypdf_metadata_xmp.py ├── csv_numpy.py ├── opencv_flip.py ├── opencv_videocapture_read_camera.py ├── numpy_random_distributions.py ├── numpy_image_split_color.py ├── numpy_vsplit.py ├── opencv_videocapture_play_file.py ├── opencv_videocapture_realtime.py ├── pass_exception.py ├── str_num_conversion_unicodedata.py ├── for_range.py ├── str_remove_slice.py ├── calendar_leap.py ├── pathlib_cwd.py ├── opencv_add_weighted.py ├── jupyter_precision_pandas.py ├── matplotlib_seaborn.py ├── platform_usage_win.py ├── sklearn_confusion_matrix_heatmap.py ├── dict_swap_key_value.py ├── any_example.py ├── matplotlib_patches.py ├── sys_version.py ├── dict_comprehension.py ├── dict_get.py ├── platform_usage_ubuntu.py ├── collections_counter_timeit.py ├── os_removedirs.py ├── pillow_image.py ├── pillow_size.py ├── import_example_from.py ├── pandas_str_num_conversion_separator.py ├── tensorflow_variable.py ├── mojimoji_usage.py ├── numpy_ndarray_example.py ├── int_bit_count.py ├── matplotlib_example_multi.py ├── all_any_comprehension.py ├── numpy_image_paste.py ├── numpy_select_basic.py ├── opencv_mosaic_gif.py ├── pillow_image_draw.py ├── numpy_pil_conversion.py ├── re_compile.py └── numpy_allclose.py └── README.md /notebook/data/temp/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /notebook/my_package/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /notebook/hello_direct.py: -------------------------------------------------------------------------------- 1 | print('Hello!') 2 | -------------------------------------------------------------------------------- /notebook/my_package/sub_package1/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /notebook/my_package/sub_package2/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /notebook/data/dst/target_2.txt: -------------------------------------------------------------------------------- 1 | !! This is "target_2.txt" !! -------------------------------------------------------------------------------- /notebook/data/src/sample_quote.csv: -------------------------------------------------------------------------------- 1 | 1,2,"3" 2 | "a,b,c",x,y -------------------------------------------------------------------------------- /notebook/data/src/target_1.txt: -------------------------------------------------------------------------------- 1 | !! This is "target_1.txt" !! -------------------------------------------------------------------------------- /notebook/data/src/test.txt: -------------------------------------------------------------------------------- 1 | line 1 2 | line 2 3 | line 3 -------------------------------------------------------------------------------- /notebook/data/src/sample_linebreak.csv: -------------------------------------------------------------------------------- 1 | 1,2,"3" 2 | "a 3 | b",x,y -------------------------------------------------------------------------------- /notebook/data/src/unicode_escape.txt: -------------------------------------------------------------------------------- 1 | \u3042\u3044\u3046\u3048\u304a -------------------------------------------------------------------------------- /notebook/data/src/sample.csv: -------------------------------------------------------------------------------- 1 | 11,12,13,14 2 | 21,22,23,24 3 | 31,32,33,34 -------------------------------------------------------------------------------- /notebook/data/src/sample.txt: -------------------------------------------------------------------------------- 1 | 11 12 13 14 2 | 21 22 23 24 3 | 31 32 33 34 -------------------------------------------------------------------------------- /notebook/data/src/sample_nan.csv: -------------------------------------------------------------------------------- 1 | 11,12,,14 2 | 21,,,24 3 | 31,32,33,34 -------------------------------------------------------------------------------- /notebook/sys_exit_stderr.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | sys.exit('Error message') 4 | -------------------------------------------------------------------------------- /notebook/data/src/sample_double_quotation.csv: -------------------------------------------------------------------------------- 1 | "one,one", "two,two", "three,three" -------------------------------------------------------------------------------- /notebook/data/src/test_u.json: -------------------------------------------------------------------------------- 1 | {"A": "\u3042\u3044\u3046\u3048\u304a", "B": "abc"} -------------------------------------------------------------------------------- /notebook/my_package/mod1.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('-- mod1.func is called') 3 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_header_index.csv: -------------------------------------------------------------------------------- 1 | 24,NY,64 2 | 42,CA,92 3 | 18,CA,70 4 | -------------------------------------------------------------------------------- /notebook/data/src/sample_space.csv: -------------------------------------------------------------------------------- 1 | 11, 12, 13, 14 2 | 21, 22, 23, 24 3 | 31, 32, 33, 34 -------------------------------------------------------------------------------- /notebook/dir_import_test/mod1.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('-- mod1.func is called') 3 | -------------------------------------------------------------------------------- /notebook/data/src/sample_for_grep.txt: -------------------------------------------------------------------------------- 1 | XXX YYY ZZZ 2 | YYY 3 | aaa 4 | XXX 5 | ZZZ XXX 6 | xxx -------------------------------------------------------------------------------- /notebook/data/src/sample_header.csv: -------------------------------------------------------------------------------- 1 | a,b,c,d 2 | 11,12,13,14 3 | 21,22,23,24 4 | 31,32,33,34 -------------------------------------------------------------------------------- /notebook/pass_if.py: -------------------------------------------------------------------------------- 1 | a = 3 2 | if a % 2 == 0: 3 | print('Even') 4 | else: 5 | pass 6 | -------------------------------------------------------------------------------- /notebook/print_sys_path.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pprint 3 | 4 | pprint.pprint(sys.path) 5 | -------------------------------------------------------------------------------- /notebook/builtin_functions.py: -------------------------------------------------------------------------------- 1 | print(len([0, 1, 2])) 2 | # 3 3 | 4 | print(abs(-10)) 5 | # 10 6 | -------------------------------------------------------------------------------- /notebook/data/src/sample_header_index_nan.csv: -------------------------------------------------------------------------------- 1 | ,a,b 2 | ONE,,NaN 3 | TWO,-,nan 4 | THREE,null,N/A -------------------------------------------------------------------------------- /notebook/doctest_example_testfile.py: -------------------------------------------------------------------------------- 1 | import doctest 2 | doctest.testfile('doctest_text.txt') 3 | -------------------------------------------------------------------------------- /notebook/hello.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('Hello!') 3 | print('__name__ is', __name__) 4 | -------------------------------------------------------------------------------- /notebook/input_usage_script.py: -------------------------------------------------------------------------------- 1 | val = input('Enter your name: ') 2 | 3 | print('You are', val) 4 | -------------------------------------------------------------------------------- /notebook/my_package/main.py: -------------------------------------------------------------------------------- 1 | from sub_package2 import sub_mod2 2 | 3 | sub_mod2.func_parent() 4 | -------------------------------------------------------------------------------- /notebook/add_module_import.py: -------------------------------------------------------------------------------- 1 | import add_module 2 | 3 | print(add_module.add(100, 200)) 4 | # 300 5 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_columns.csv: -------------------------------------------------------------------------------- 1 | name,age,point 2 | Alice,24,64 3 | Bob,42,92 4 | Charlie,18,70 5 | -------------------------------------------------------------------------------- /notebook/data/src/lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena.jpg -------------------------------------------------------------------------------- /notebook/data/src/test.json: -------------------------------------------------------------------------------- 1 | {"A": {"X": 1, "Y": 1.0, "Z": "abc"}, "B": [true, false, null, NaN, Infinity]} -------------------------------------------------------------------------------- /notebook/my_package/sub_package1/sub_mod1.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('-- sub_mod1.func1 is called') 3 | -------------------------------------------------------------------------------- /notebook/sys_exit.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print('Start') 4 | 5 | sys.exit() 6 | 7 | print('Finish') 8 | -------------------------------------------------------------------------------- /notebook/data/src/horse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/horse.png -------------------------------------------------------------------------------- /notebook/data/src/md/test2.md: -------------------------------------------------------------------------------- 1 | - [[Py] Python.org](https://www.python.org/) 2 | - [relative link](../test/) 3 | -------------------------------------------------------------------------------- /notebook/data/src/qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/qrcode.png -------------------------------------------------------------------------------- /notebook/data/src/rocket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/rocket.jpg -------------------------------------------------------------------------------- /notebook/data/src/sample_header_index.csv: -------------------------------------------------------------------------------- 1 | ,a,b,c,d 2 | ONE,11,12,13,14 3 | TWO,21,22,23,24 4 | THREE,31,32,33,34 -------------------------------------------------------------------------------- /notebook/data/src/sample_header_index.tsv: -------------------------------------------------------------------------------- 1 | a b c d 2 | ONE 11 12 13 14 3 | TWO 21 22 23 24 4 | THREE 31 32 33 34 -------------------------------------------------------------------------------- /notebook/dir_import_test/dir_for_mod/mod2.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('-- dir_for_mod.mod2.func is called') 3 | -------------------------------------------------------------------------------- /notebook/data/dst/lena_flip.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_flip.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_q25.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_q25.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_swap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_swap.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_th.jpg -------------------------------------------------------------------------------- /notebook/data/dst/qr_lena.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qr_lena.png -------------------------------------------------------------------------------- /notebook/data/dst/qr_lena2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qr_lena2.png -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point 2 | Alice,24,NY,64 3 | Bob,42,CA,92 4 | Charlie,18,CA,70 5 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out.tsv: -------------------------------------------------------------------------------- 1 | name age state point 2 | Alice 24 NY 64 3 | Bob 42 CA 92 4 | Charlie 18 CA 70 5 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_nan.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point 2 | Alice,24,,64.0 3 | Bob,42,CA, 4 | Charlie,18,CA,70.0 5 | -------------------------------------------------------------------------------- /notebook/data/src/barcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/barcode.jpg -------------------------------------------------------------------------------- /notebook/data/src/horse_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/horse_r.png -------------------------------------------------------------------------------- /notebook/data/src/lena_q50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena_q50.jpg -------------------------------------------------------------------------------- /notebook/data/src/lena_q95.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena_q95.jpg -------------------------------------------------------------------------------- /notebook/data/src/sample.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/sample.xlsx -------------------------------------------------------------------------------- /notebook/doctest_text.txt: -------------------------------------------------------------------------------- 1 | >>> from doctest_example import add 2 | >>> add(1, 2) 3 | 3 4 | >>> add(5, 10) 5 | 15 6 | -------------------------------------------------------------------------------- /notebook/hello_main.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | print('Hello!') 3 | 4 | 5 | if __name__ == '__main__': 6 | main() 7 | -------------------------------------------------------------------------------- /notebook/locale_getpreferredencoding.py: -------------------------------------------------------------------------------- 1 | import locale 2 | 3 | print(locale.getpreferredencoding()) 4 | # UTF-8 5 | -------------------------------------------------------------------------------- /notebook/data/dst/horse_flip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/horse_flip.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_bgr_cv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_bgr_cv.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_invert.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_invert.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_mirror.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_mirror.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rgb_cv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rgb_cv.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_swap_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_swap_2.jpg -------------------------------------------------------------------------------- /notebook/data/dst/mask_circle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/mask_circle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_obj.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_obj.pkl -------------------------------------------------------------------------------- /notebook/data/dst/pandas_obj.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_obj.zip -------------------------------------------------------------------------------- /notebook/data/dst/pandas_pie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_pie.png -------------------------------------------------------------------------------- /notebook/data/dst/qrcode_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qrcode_test.png -------------------------------------------------------------------------------- /notebook/data/dst/xlwt_sample.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/xlwt_sample.xls -------------------------------------------------------------------------------- /notebook/data/src/gradation_h.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/gradation_h.jpg -------------------------------------------------------------------------------- /notebook/data/src/lena_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena_square.png -------------------------------------------------------------------------------- /notebook/data/src/pdf/sample1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/pdf/sample1.pdf -------------------------------------------------------------------------------- /notebook/data/src/pdf/sample2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/pdf/sample2.pdf -------------------------------------------------------------------------------- /notebook/data/src/pdf/sample3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/pdf/sample3.pdf -------------------------------------------------------------------------------- /notebook/data/src/sample_header_index_dtype.csv: -------------------------------------------------------------------------------- 1 | ,a,b,c,d 2 | ONE,1,"001",100,x 3 | TWO,2,"020",,y 4 | THREE,3,"300",300,z -------------------------------------------------------------------------------- /notebook/data/dst/barcode_opencv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/barcode_opencv.jpg -------------------------------------------------------------------------------- /notebook/data/dst/color_gradient.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/color_gradient.jpg -------------------------------------------------------------------------------- /notebook/data/dst/horse_invert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/horse_invert.png -------------------------------------------------------------------------------- /notebook/data/dst/horse_mirror.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/horse_mirror.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_bgr_cv_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_bgr_cv_2.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_diff_abs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_diff_abs.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_diff_bin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_diff_bin.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_fliplr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_fliplr.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_flipud.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_flipud.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_rot90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_rot90.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_90.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_hconcat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_hconcat.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_th_otsu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_th_otsu.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_th_tz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_th_tz.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_vconcat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_vconcat.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_voronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_voronoi.png -------------------------------------------------------------------------------- /notebook/data/dst/qrcode_opencv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qrcode_opencv.jpg -------------------------------------------------------------------------------- /notebook/data/dst/qrcode_test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qrcode_test2.png -------------------------------------------------------------------------------- /notebook/data/dst/qrcode_test2_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/qrcode_test2_2.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_iris.png -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_nan_rep.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point 2 | Alice,24,NaN,64.0 3 | Bob,42,CA,NaN 4 | Charlie,18,CA,70.0 5 | -------------------------------------------------------------------------------- /notebook/data/src/astronaut_rect.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/astronaut_rect.bmp -------------------------------------------------------------------------------- /notebook/data/src/barcode_qrcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/barcode_qrcode.jpg -------------------------------------------------------------------------------- /notebook/data/src/horse_r_resize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/horse_r_resize.png -------------------------------------------------------------------------------- /notebook/data/src/md/sub_dir/test_sub.md: -------------------------------------------------------------------------------- 1 | - [Instagram](https://www.instagram.com/) 2 | - [Twitter](https://twitter.com)) 3 | -------------------------------------------------------------------------------- /notebook/data/src/rocket_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/rocket_resize.jpg -------------------------------------------------------------------------------- /notebook/pass_with_open.py: -------------------------------------------------------------------------------- 1 | with open('temp/empty.txt', 'w'): 2 | pass 3 | 4 | with open('temp/empty.txt', 'w'): pass 5 | -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_day.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_day.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_week.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_week.png -------------------------------------------------------------------------------- /notebook/data/dst/gray_gradient_h.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/gray_gradient_h.jpg -------------------------------------------------------------------------------- /notebook/data/dst/gray_gradient_v.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/gray_gradient_v.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_bgr_pillow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_bgr_pillow.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_flip_lr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_flip_lr.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_flip_ud.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_flip_ud.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_diff_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_diff_center.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_gamma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_gamma.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_gray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_gray.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_paste.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_paste.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_roll.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_roll.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_tile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_tile.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_trim.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_trim.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_trim2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_trim2.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_trim3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_trim3.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_opencv_gray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_opencv_gray.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_opencv_red.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_opencv_red.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rgb_pillow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rgb_pillow.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_square_face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_square_face.jpg -------------------------------------------------------------------------------- /notebook/data/dst/mask_circle_blur.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/mask_circle_blur.jpg -------------------------------------------------------------------------------- /notebook/data/dst/numpy_gray_calc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_gray_calc.jpg -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_mask.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_mask.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_delaunay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_delaunay.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_draw_etc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_draw_etc.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_draw_mask.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_draw_mask.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_mosaic_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_mosaic_01.jpg -------------------------------------------------------------------------------- /notebook/data/dst/openpyxl_sample.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/openpyxl_sample.xlsx -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_area.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_area.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_bar.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_barh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_barh.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_box.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_hist.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_hist.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_kde.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_kde.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_to_excel.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_to_excel.xlsx -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw.gif -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_block_00.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_block_00.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_block_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_block_01.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_block_10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_block_10.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_block_11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_block_11.jpg -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_float_default.csv: -------------------------------------------------------------------------------- 1 | ,col1,col2,col3 2 | 0,0.123456789,123456789.0,123456789 3 | 1,1000000000.0,0.0,0 4 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_float_format_3e.csv: -------------------------------------------------------------------------------- 1 | ,col1,col2,col3 2 | 0,1.235e-01,1.235e+08,123456789 3 | 1,1.000e+09,0.000e+00,0 4 | -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_float_format_3f.csv: -------------------------------------------------------------------------------- 1 | ,col1,col2,col3 2 | 0,0.123,123456789.000,123456789 3 | 1,1000000000.000,0.000,0 4 | -------------------------------------------------------------------------------- /notebook/data/src/lena_square_half.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena_square_half.png -------------------------------------------------------------------------------- /notebook/data/src/sample_from_pandas_columns.json: -------------------------------------------------------------------------------- 1 | {"col1":{"row1":1,"row2":2,"row3":3},"col2":{"row1":"a","row2":"x","row3":"\u3042"}} -------------------------------------------------------------------------------- /notebook/dir_import_test/dir/main_absolute.py: -------------------------------------------------------------------------------- 1 | import mod1 2 | from dir_for_mod import mod2 3 | 4 | mod1.func() 5 | mod2.func() 6 | -------------------------------------------------------------------------------- /notebook/add_module_command.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import add_module 3 | 4 | print(add_module.add(int(sys.argv[1]), int(sys.argv[2]))) 5 | -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_mav.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_mav.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_week_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_week_v.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_flip_ud_lr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_flip_ud_lr.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_rotate_180.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_rotate_180.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_diff_abs_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_diff_abs_norm.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_flip_ud_lr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_flip_ud_lr.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_rot90_180.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_rot90_180.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_np_rot90_270.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_np_rot90_270.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_inverse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_inverse.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_split_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_split_0.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_split_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_split_1.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_opencv_red_low.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_opencv_red_low.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_square_pillow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_square_pillow.jpg -------------------------------------------------------------------------------- /notebook/data/dst/mask_circle_blur2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/mask_circle_blur2.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_patches.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_patches.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_ab_grad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_ab_grad.jpg -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_mask_l.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_mask_l.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_add_weighted.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_add_weighted.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_flags.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_flags.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_half.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_half.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_bitwise_and.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_bitwise_and.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_concat_tile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_concat_tile.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_gray_cvtcolr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_gray_cvtcolr.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_gray_imread.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_gray_imread.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_hconcat_np.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_hconcat_np.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_mosaic_005.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_mosaic_005.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_mosaic_area.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_mosaic_area.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_mosaic_face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_mosaic_face.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_random_pts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_random_pts.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_vconcat_np.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_vconcat_np.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_voronoi_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_voronoi_fill.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_hexbin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_hexbin.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_x.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_xy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_xy.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_y.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_y.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_scatter.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_stacked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_stacked.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_obj.csv: -------------------------------------------------------------------------------- 1 | ,list 2 | 2018-01-01,"[0, 0]" 3 | 2018-01-02,"[0, 1]" 4 | 2018-01-03,"[1, 0]" 5 | 2018-01-04,"[1, 1]" 6 | -------------------------------------------------------------------------------- /notebook/data/dst/pandas_pie_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_pie_single.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_cut.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_cut.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v_cut.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v_cut.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_iamge_draw.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_iamge_draw.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw2.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw3.jpg -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste.jpg -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_big.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_hot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_hot.png -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve.png -------------------------------------------------------------------------------- /notebook/data/src/sample_header.csv.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/sample_header.csv.zip -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_add_margin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_add_margin.jpg -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_pillow_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_pillow_crop.jpg -------------------------------------------------------------------------------- /notebook/data/dst/barcode_qrcode_opencv.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/barcode_qrcode_opencv.jpg -------------------------------------------------------------------------------- /notebook/data/dst/barcode_qrcode_pillow.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/barcode_qrcode_pillow.jpg -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_week.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_week.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_week_sma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_week_sma.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_diff_center_norm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_diff_center_norm.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_dec_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_dec_color.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_paste_all.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_paste_all.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_swap_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_swap_color.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_opencv_red_high.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_opencv_red_high.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_90_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_90_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_test.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_skew_x.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_skew_x.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_skew_y.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_skew_y.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_concat_tile_np.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_concat_tile_np.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_delaunay_inner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_delaunay_inner.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_draw_argument.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_draw_argument.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_draw_mask_blur.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_draw_mask_blur.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_hconcat_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_hconcat_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_vconcat_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_vconcat_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_dst_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_dst_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_rectangle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_rectangle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_src_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_src_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_triangle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_triangle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_wb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_wb.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_bar_stack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_bar_stack.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_axes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_axes.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_dpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_dpi.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_etc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_etc.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_blank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_blank.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v_blank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v_blank.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_lena.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_lena.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_putalpha_horse.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_putalpha_horse.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_putalpha_solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_putalpha_solid.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_annot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_annot.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_big_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_big_2.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_blues.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_blues.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_list.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_hue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_hue.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_kws.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_kws.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_size.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_vars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_vars.png -------------------------------------------------------------------------------- /notebook/data/dst/skimage_block_change.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_block_change.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_montage_fill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_montage_fill.jpg -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve_all.png -------------------------------------------------------------------------------- /notebook/data/src/lena_square_gray_half.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/lena_square_gray_half.png -------------------------------------------------------------------------------- /notebook/data/src/pdf/sample1_pass_aes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/pdf/sample1_pass_aes.pdf -------------------------------------------------------------------------------- /notebook/data/src/pdf/sample1_pass_rc4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/pdf/sample1_pass_rc4.pdf -------------------------------------------------------------------------------- /notebook/dir_import_test/dir/main_relative.py: -------------------------------------------------------------------------------- 1 | from .. import mod1 2 | from ..dir_for_mod import mod2 3 | 4 | mod1.func() 5 | mod2.func() 6 | -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_expand_square.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_expand_square.jpg -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_day_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_day_format.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_candle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_candle.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_figratio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_figratio.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_volume.png -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_week_sma_v.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_week_sma_v.png -------------------------------------------------------------------------------- /notebook/data/dst/iris_pandas_groupby_max.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/iris_pandas_groupby_max.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_binarization.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_binarization.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_split_color.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_split_color.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_opencv_face_detect.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_opencv_face_detect.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_pillow_resize_half.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_pillow_resize_half.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_0_translate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_0_translate.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_bicubic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_bicubic.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_translate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_translate.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_square_pillow_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_square_pillow_crop.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_example_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_example_multi.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_paper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_paper.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_ticks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_ticks.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_classic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_classic.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_default.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_ggplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_ggplot.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization_color.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization_keep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization_keep.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_ab_mask_grad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_ab_mask_grad.jpg -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_alpha_blend.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_alpha_blend.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_mark_dst.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_mark_dst.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_mark_src.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_mark_src.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_delaunay_voronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_delaunay_voronoi.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_face_detect_fill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_face_detect_fill.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_perspective_dst.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_perspective_dst.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_affine_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_affine_crop.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_dst_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_dst_result.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_stock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_stock.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_yahoo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_yahoo.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_hist_alpha.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_hist_alpha.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_hist_h_step.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_hist_h_step.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_figsize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_figsize.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_multi.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_style.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_scatter_line.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_scatter_line.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_to_excel_multi.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_to_excel_multi.xlsx -------------------------------------------------------------------------------- /notebook/data/dst/pillow_composite_circle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_composite_circle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_composite_horse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_composite_horse.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_composite_solid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_composite_solid.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text_ja.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text_ja.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_putalpha_circle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_putalpha_circle.png -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste_out.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste_out.jpg -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste_pos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste_pos.jpg -------------------------------------------------------------------------------- /notebook/data/dst/scipy_matplotlib_voronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/scipy_matplotlib_voronoi.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_blues_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_blues_r.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_list_sub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_list_sub.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_ndarray.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_ndarray.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_no_cbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_no_cbar.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_square.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_default.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_markers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_markers.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_palette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_palette.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_xy_vars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_xy_vars.png -------------------------------------------------------------------------------- /notebook/data/dst/skimage_montage_1_3_pad.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_montage_1_3_pad.jpg -------------------------------------------------------------------------------- /notebook/data/dst/skimage_montage_default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/skimage_montage_default.jpg -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_confusion_matrix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_confusion_matrix.png -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve_random.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve_random.png -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve_same.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve_same.png -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_float_format_str.csv: -------------------------------------------------------------------------------- 1 | ,col1,col2,col3 2 | 0,0.123,1.235e+08,0x075bcd15 3 | 1,1000000000.000,0.000e+00,0x00000000 4 | -------------------------------------------------------------------------------- /notebook/data/src/sample_header_shift_jis.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/sample_header_shift_jis.csv -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_thumbnail_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_thumbnail_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_pillow_resize_lanczos.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_pillow_resize_lanczos.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_pillow_resize_nearest.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_pillow_resize_nearest.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_example_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_example_single.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_histogram_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_histogram_multi.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_mplot3d_scatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_mplot3d_scatter.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_mplot3d_surface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_mplot3d_surface.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_default.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_poster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_poster.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_set_all.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_set_all.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_winter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_winter.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization_color2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization_color2.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_add_weighted_gamma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_add_weighted_gamma.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_border_value.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_border_value.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_border_wrap.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_border_wrap.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_translation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_translation.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_concat_tile_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_concat_tile_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_face_detect_mosaic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_face_detect_mosaic.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_dst_crop_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_dst_crop_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_src_crop_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_src_crop_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_subplots.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_subplots.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_scatter_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_scatter_multi.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_composite_gradation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_composite_gradation.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_cut_center.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_cut_center.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_tile_repeat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_tile_repeat.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_tile_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_tile_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v_cut_center.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v_cut_center.jpg -------------------------------------------------------------------------------- /notebook/data/dst/scipy_matplotlib_delaunay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/scipy_matplotlib_delaunay.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_dataframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_dataframe.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_hue_order.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_hue_order.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_kind_reg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_kind_reg.png -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve_compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve_compare.png -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_roc_curve_perfect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_roc_curve_perfect.png -------------------------------------------------------------------------------- /notebook/data/src/sample_from_pandas_columns.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/src/sample_from_pandas_columns.gz -------------------------------------------------------------------------------- /notebook/builtin_types.py: -------------------------------------------------------------------------------- 1 | s = 'abc' 2 | 3 | print(s) 4 | # abc 5 | 6 | print(type(s)) 7 | # 8 | 9 | print(s.upper()) 10 | # ABC 11 | -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_pillow_crop_center.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_pillow_crop_center.jpg -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_pillow_crop_outside.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_pillow_crop_outside.jpg -------------------------------------------------------------------------------- /notebook/data/dst/candlestick_mpf_style_yahoo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/candlestick_mpf_style_yahoo.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_rotate_90_clockwise.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_rotate_90_clockwise.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_binarization_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_binarization_color.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_change_center.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_change_center.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_expand_bicubic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_expand_bicubic.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_histogram_single.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_histogram_single.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_mplot3d_wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_mplot3d_wireframe.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_paper_bold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_paper_bold.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_whitegrid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_whitegrid.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_winter_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_winter_r.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_test_ggplot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_test_ggplot.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization_from_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization_from_color.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_image_alpha_blend_gamma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_image_alpha_blend_gamma.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_mark_dst_mark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_mark_dst_mark.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_draw_mask_blur_result.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_draw_mask_blur_result.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_face_detect_rectangle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_face_detect_rectangle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_warp_affine_crop_merge.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_warp_affine_crop_merge.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_morningstar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_morningstar.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_composite_circle_blur.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_composite_circle_blur.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_multi_blank.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_multi_blank.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_h_multi_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_h_multi_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_concat_v_multi_resize.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_concat_v_multi_resize.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text_anchor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text_anchor.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text_arial.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text_arial.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_putalpha_circle_blur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_putalpha_circle_blur.png -------------------------------------------------------------------------------- /notebook/data/dst/scipy_matplotlib_voronoi_fill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/scipy_matplotlib_voronoi_fill.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_corr_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_corr_example.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_house_price.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_house_price.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_kind_reg_kws.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_kind_reg_kws.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_palette_dict.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_palette_dict.png -------------------------------------------------------------------------------- /notebook/math_ulp.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.ulp(0.0)) 4 | # 5e-324 5 | 6 | print(format(math.ulp(0.0), '.17')) 7 | # 4.9406564584124654e-324 8 | -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_thumbnail_max_square.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_thumbnail_max_square.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_numpy_binarization_color2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_numpy_binarization_color2.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_fillcolor_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_fillcolor_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_translate_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_translate_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_square_pillow_crop_center.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_square_pillow_crop_center.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_square_pillow_crop_outside.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_square_pillow_crop_outside.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_winter_desat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_winter_desat.png -------------------------------------------------------------------------------- /notebook/data/dst/numpy_binarization_from_color2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/numpy_binarization_from_color2.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_border_replicate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_border_replicate.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_mark_dst_another.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_mark_dst_another.jpg -------------------------------------------------------------------------------- /notebook/data/dst/opencv_perspective_dst_inverse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_perspective_dst_inverse.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_subplots_share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_subplots_share.png -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text_multiline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text_multiline.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pillow_imagedraw_text_textbbox.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pillow_imagedraw_text_textbbox.jpg -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste_mask_circle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste_mask_circle.jpg -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste_mask_horse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste_mask_horse.jpg -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_diag_kind_kde.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_diag_kind_kde.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_pairplot_markers_multi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_pairplot_markers_multi.png -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_a_new_column.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point,new_col 2 | Alice,24,NY,64,new data 3 | Bob,42,CA,92,new data 4 | Charlie,18,CA,70,new data 5 | -------------------------------------------------------------------------------- /notebook/hello_if_name.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print('Hello!') 3 | print('__name__ is', __name__) 4 | 5 | 6 | if __name__ == '__main__': 7 | func() 8 | -------------------------------------------------------------------------------- /notebook/standard_library_example.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.cos(0)) 4 | # 1.0 5 | 6 | from math import sin 7 | 8 | print(sin(0)) 9 | # 0.0 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-snippets 2 | 3 | - Japanese: [https://note.nkmk.me](https://note.nkmk.me) 4 | - English: [https://note.nkmk.me/en/](https://note.nkmk.me/en/) 5 | -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_pillow_crop_max_square.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_pillow_crop_max_square.jpg -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_thumbnail_center_square.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_thumbnail_center_square.jpg -------------------------------------------------------------------------------- /notebook/data/dst/lena_cv_rotate_90_counterclockwise.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_cv_rotate_90_counterclockwise.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_dark_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_dark_background.png -------------------------------------------------------------------------------- /notebook/data/dst/opencv_affine_border_transparent.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/opencv_affine_border_transparent.jpg -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_stock_normalize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_stock_normalize.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_iris_line_subplots_layout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_iris_line_subplots_layout.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_to_excel_no_index_header.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_to_excel_no_index_header.xlsx -------------------------------------------------------------------------------- /notebook/data/dst/scipy_matplotlib_delaunay_voronoi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/scipy_matplotlib_delaunay_voronoi.png -------------------------------------------------------------------------------- /notebook/data/dst/seaborn_heatmap_vmax_vmin_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/seaborn_heatmap_vmax_vmin_center.png -------------------------------------------------------------------------------- /notebook/data/dst/lena_rotate_45_change_center_expand.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/lena_rotate_45_change_center_expand.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_seaborn_whitegrid_dashed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_seaborn_whitegrid_dashed.png -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_change_axes_margin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_change_axes_margin.png -------------------------------------------------------------------------------- /notebook/data/dst/rocket_pillow_paste_mask_circle_blur.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/rocket_pillow_paste_mask_circle_blur.jpg -------------------------------------------------------------------------------- /notebook/data/dst/sklearn_confusion_matrix_annot_blues.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/sklearn_confusion_matrix_annot_blues.png -------------------------------------------------------------------------------- /notebook/data/dst/to_csv_out_a.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point 2 | Alice,24,NY,64 3 | Bob,42,CA,92 4 | Charlie,18,CA,70 5 | Alice,24,NY,64 6 | Bob,42,CA,92 7 | Charlie,18,CA,70 8 | -------------------------------------------------------------------------------- /notebook/data/src/sample_pandas_normal_nan.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point,other 2 | Alice,24,NY,, 3 | ,,,, 4 | Charlie,,CA,, 5 | Dave,68,TX,70, 6 | Ellen,,CA,88, 7 | Frank,30,,, -------------------------------------------------------------------------------- /notebook/data/src/test.mplstyle: -------------------------------------------------------------------------------- 1 | lines.linewidth : 3.0 2 | lines.linestyle : -- # 破線 3 | axes.prop_cycle : cycler('color', ['green']) 4 | axes.grid : True -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_thumbnail_mask_circle_solid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_thumbnail_mask_circle_solid.jpg -------------------------------------------------------------------------------- /notebook/data/dst/matplotlib_style_ggplot_dark_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/matplotlib_style_ggplot_dark_background.png -------------------------------------------------------------------------------- /notebook/data/dst/pandas_datareader_morningstar_normalize.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/pandas_datareader_morningstar_normalize.png -------------------------------------------------------------------------------- /notebook/data/src/sample_pandas_normal.csv: -------------------------------------------------------------------------------- 1 | name,age,state,point 2 | Alice,24,NY,64 3 | Bob,42,CA,92 4 | Charlie,18,CA,70 5 | Dave,68,TX,70 6 | Ellen,24,CA,88 7 | Frank,30,NY,57 -------------------------------------------------------------------------------- /notebook/data/dst/astronaut_thumbnail_mask_circle_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nkmk/python-snippets/HEAD/notebook/data/dst/astronaut_thumbnail_mask_circle_transparent.png -------------------------------------------------------------------------------- /notebook/inf_math.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.inf) 4 | # inf 5 | 6 | print(type(math.inf)) 7 | # 8 | 9 | print(float('inf') == math.inf) 10 | # True 11 | -------------------------------------------------------------------------------- /notebook/add_module.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | 4 | def add(a, b): 5 | return a + b 6 | 7 | 8 | if __name__ == '__main__': 9 | print(add(int(sys.argv[1]), int(sys.argv[2]))) 10 | -------------------------------------------------------------------------------- /notebook/inf_numpy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.inf) 4 | # inf 5 | 6 | print(type(np.inf)) 7 | # 8 | 9 | print(float('inf') == np.inf) 10 | # True 11 | -------------------------------------------------------------------------------- /notebook/sys_exit_systemexit.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print('Start') 4 | 5 | try: 6 | sys.exit() 7 | except: 8 | print('Catch all exceptions') 9 | 10 | print('Finish') 11 | -------------------------------------------------------------------------------- /notebook/third_party_library_example.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.array([0, 1, 2]) 4 | 5 | print(a) 6 | # [0 1 2] 7 | 8 | print(type(a)) 9 | # 10 | -------------------------------------------------------------------------------- /notebook/data/src/md/test1.md: -------------------------------------------------------------------------------- 1 | [Instagram](https://www.instagram.com/) and [Twitter](https://twitter.com) 2 | 3 | - [[Py] Python.org](https://www.python.org/) 4 | - [relative link](../test/) 5 | -------------------------------------------------------------------------------- /notebook/while_keyboardinterrupt.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | try: 4 | while True: 5 | time.sleep(1) 6 | print('processing...') 7 | except KeyboardInterrupt: 8 | print('!!FINISH!!') 9 | -------------------------------------------------------------------------------- /notebook/pillow_save_lq_images.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | img = Image.open('data/src/lena.jpg') 4 | 5 | img.save('data/src/lena_q95.jpg', quality=95) 6 | img.save('data/src/lena_q50.jpg', quality=50) 7 | -------------------------------------------------------------------------------- /notebook/scipy_special_perm.py: -------------------------------------------------------------------------------- 1 | from scipy.special import perm 2 | 3 | print(perm(4, 2)) 4 | # 12.0 5 | 6 | print(perm(4, 2, exact=True)) 7 | # 12 8 | 9 | print(perm(4, 4, exact=True)) 10 | # 24 11 | -------------------------------------------------------------------------------- /notebook/is_compare.py: -------------------------------------------------------------------------------- 1 | i = 10 2 | print(type(i)) 3 | # 4 | 5 | f = 10.0 6 | print(type(f)) 7 | # 8 | 9 | print(i == f) 10 | # True 11 | 12 | print(i is f) 13 | # False 14 | -------------------------------------------------------------------------------- /notebook/sympy_from_import.py: -------------------------------------------------------------------------------- 1 | import sympy 2 | from sympy import sin, exp 3 | 4 | x = sympy.Symbol('x') 5 | 6 | print(sympy.diff(sin(x))) 7 | # cos(x) 8 | 9 | print(sympy.diff(exp(x))) 10 | # exp(x) 11 | -------------------------------------------------------------------------------- /notebook/argparse_type_int.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | parser = argparse.ArgumentParser() 4 | parser.add_argument('arg_int', type=int) 5 | 6 | args = parser.parse_args() 7 | print(args.arg_int) 8 | print(type(args.arg_int)) 9 | -------------------------------------------------------------------------------- /notebook/sklearn_f1_score.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import f1_score 2 | 3 | y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] 4 | y_pred = [0, 1, 1, 1, 1, 0, 0, 0, 1, 1] 5 | 6 | print(f1_score(y_true, y_pred)) 7 | # 0.3636363636363636 8 | -------------------------------------------------------------------------------- /notebook/sklearn_recall_score.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import recall_score 2 | 3 | y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] 4 | y_pred = [0, 1, 1, 1, 1, 0, 0, 0, 1, 1] 5 | 6 | print(recall_score(y_true, y_pred)) 7 | # 0.4 8 | -------------------------------------------------------------------------------- /notebook/sys_exit_if.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | a = 100 4 | 5 | print('Start') 6 | 7 | if a == 0: 8 | sys.exit() 9 | 10 | print('Continue') 11 | 12 | if a == 100: 13 | sys.exit() 14 | 15 | print('Finish') 16 | -------------------------------------------------------------------------------- /notebook/argparse_option_bool.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | parser = argparse.ArgumentParser() 4 | parser.add_argument('--en', action='store_true') 5 | 6 | args = parser.parse_args() 7 | print(args.en) 8 | print(type(args.en)) 9 | -------------------------------------------------------------------------------- /notebook/argparse_type_bool.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | parser = argparse.ArgumentParser() 4 | parser.add_argument('arg_bool', type=bool) 5 | 6 | args = parser.parse_args() 7 | print(args.arg_bool) 8 | print(type(args.arg_bool)) 9 | -------------------------------------------------------------------------------- /notebook/numpy_linalg_det.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.2 5 | 6 | a = np.array([[0, 1], [2, 3]]) 7 | print(a) 8 | # [[0 1] 9 | # [2 3]] 10 | 11 | print(np.linalg.det(a)) 12 | # -2.0 13 | -------------------------------------------------------------------------------- /notebook/sklearn_accuracy_score.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import accuracy_score 2 | 3 | y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] 4 | y_pred = [0, 1, 1, 1, 1, 0, 0, 0, 1, 1] 5 | 6 | print(accuracy_score(y_true, y_pred)) 7 | # 0.3 8 | -------------------------------------------------------------------------------- /notebook/calendar_weekday.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | print(calendar.weekday(2023, 1, 1)) 4 | # 6 5 | 6 | w_list = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'] 7 | 8 | print(w_list[calendar.weekday(2023, 1, 1)]) 9 | # Su 10 | -------------------------------------------------------------------------------- /notebook/gcd_lcm.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.gcd(6, 4)) 4 | # 2 5 | 6 | print(math.lcm(6, 4)) 7 | # 12 8 | 9 | def my_lcm(x, y): 10 | return (x * y) // math.gcd(x, y) 11 | 12 | print(my_lcm(6, 4)) 13 | # 12 14 | -------------------------------------------------------------------------------- /notebook/test_main.py: -------------------------------------------------------------------------------- 1 | import test_module 2 | 3 | print('This is test_main.py') 4 | print('test_module.__name__ is', test_module.__name__) 5 | 6 | print('---') 7 | print('call test_module.func()') 8 | 9 | test_module.func() 10 | -------------------------------------------------------------------------------- /notebook/import_example_pep.py: -------------------------------------------------------------------------------- 1 | # Wrong: 2 | import os, sys 3 | 4 | # Correct: 5 | import os 6 | import sys 7 | 8 | import math 9 | import os 10 | import sys 11 | 12 | import Requests 13 | 14 | import my_package1 15 | import my_package2 16 | -------------------------------------------------------------------------------- /notebook/sklearn_precision_score.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import precision_score 2 | 3 | y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] 4 | y_pred = [0, 1, 1, 1, 1, 0, 0, 0, 1, 1] 5 | 6 | print(precision_score(y_true, y_pred)) 7 | # 0.3333333333333333 8 | -------------------------------------------------------------------------------- /notebook/dir_import_test/dir/main_sys_path_append.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | sys.path.append(os.path.join(os.path.dirname(__file__), '..')) 5 | 6 | import mod1 7 | from dir_for_mod import mod2 8 | 9 | mod1.func() 10 | mod2.func() 11 | -------------------------------------------------------------------------------- /notebook/numpy_image_inverse.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | im = np.array(Image.open('data/src/lena_square.png').resize((256, 256))) 5 | 6 | im_i = 255 - im 7 | 8 | Image.fromarray(im_i).save('data/dst/lena_numpy_inverse.jpg') 9 | -------------------------------------------------------------------------------- /notebook/ellipsis_object.py: -------------------------------------------------------------------------------- 1 | print(Ellipsis) 2 | # Ellipsis 3 | 4 | print(...) 5 | # Ellipsis 6 | 7 | print(type(Ellipsis)) 8 | # 9 | 10 | print(type(...)) 11 | # 12 | 13 | print(Ellipsis is ...) 14 | # True 15 | -------------------------------------------------------------------------------- /notebook/numpy_max.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.arange(6).reshape(2, 3) 4 | print(a) 5 | # [[0 1 2] 6 | # [3 4 5]] 7 | 8 | print(a.max()) 9 | # 5 10 | 11 | print(a.max(axis=0)) 12 | # [3 4 5] 13 | 14 | print(a.max(axis=1)) 15 | # [2 5] 16 | -------------------------------------------------------------------------------- /notebook/save_file_at_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | def save_file_at_dir(dir_path, filename, file_content, mode='w'): 4 | os.makedirs(dir_path, exist_ok=True) 5 | with open(os.path.join(dir_path, filename), mode) as f: 6 | f.write(file_content) 7 | -------------------------------------------------------------------------------- /notebook/str_replace_with_empty.py: -------------------------------------------------------------------------------- 1 | s = 'abc-xyz-123-789-ABC-XYZ' 2 | 3 | print(s.replace('xyz', '')) 4 | # abc--123-789-ABC-XYZ 5 | 6 | import re 7 | 8 | s = 'abc-xyz-123-789-ABC-XYZ' 9 | 10 | print(re.sub('\d+', '', s)) 11 | # abc-xyz---ABC-XYZ 12 | -------------------------------------------------------------------------------- /notebook/divmod-test.py: -------------------------------------------------------------------------------- 1 | q = 10 // 3 2 | mod = 10 % 3 3 | print(q, mod) 4 | # 3 1 5 | 6 | q, mod = divmod(10, 3) 7 | print(q, mod) 8 | # 3 1 9 | 10 | answer = divmod(10, 3) 11 | print(answer) 12 | print(answer[0], answer[1]) 13 | # (3, 1) 14 | # 3 1 15 | -------------------------------------------------------------------------------- /notebook/doctest_example.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | ''' 3 | >>> add(1, 2) 4 | 3 5 | >>> add(5, 10) 6 | 15 7 | ''' 8 | 9 | return a + b 10 | 11 | 12 | if __name__ == '__main__': 13 | import doctest 14 | doctest.testmod() 15 | -------------------------------------------------------------------------------- /notebook/heapq_nlargest_nsmallest.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | 3 | l = [3, 6, 7, -1, 23, -10, 18] 4 | 5 | print(heapq.nlargest(3, l)) 6 | # [23, 18, 7] 7 | 8 | print(heapq.nsmallest(3, l)) 9 | # [-10, -1, 3] 10 | 11 | print(l) 12 | # [3, 6, 7, -1, 23, -10, 18] 13 | -------------------------------------------------------------------------------- /notebook/doctest_example_error.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | ''' 3 | >>> add(1, 2) 4 | 3 5 | >>> add(5, 10) 6 | 10 7 | ''' 8 | 9 | return a * b 10 | 11 | 12 | if __name__ == '__main__': 13 | import doctest 14 | doctest.testmod() 15 | -------------------------------------------------------------------------------- /notebook/scipy_special_comb.py: -------------------------------------------------------------------------------- 1 | from scipy.special import comb 2 | 3 | print(comb(4, 2)) 4 | # 6.0 5 | 6 | print(comb(4, 2, exact=True)) 7 | # 6 8 | 9 | print(comb(4, 0, exact=True)) 10 | # 1 11 | 12 | print(comb(4, 2, exact=True, repetition=True)) 13 | # 10 14 | -------------------------------------------------------------------------------- /notebook/add_module_argparse.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import add_module 3 | 4 | parser = argparse.ArgumentParser() 5 | parser.add_argument('a', type=int) 6 | parser.add_argument('b', type=int) 7 | 8 | args = parser.parse_args() 9 | print(add_module.add(args.a, args.b)) 10 | -------------------------------------------------------------------------------- /notebook/data/src/sample_datetime_multi.csv: -------------------------------------------------------------------------------- 1 | A,B 2 | 2017-11-01 12:24,2017年11月1日 12時24分 3 | 2017-11-18 23:00,2017年11月18日 23時00分 4 | 2017-12-05 5:05,2017年12月5日 5時05分 5 | 2017-12-22 8:54,2017年12月22日 8時54分 6 | 2018-01-08 14:20,2018年1月8日 14時20分 7 | 2018-01-19 20:01,2018年1月19日 20時01分 -------------------------------------------------------------------------------- /notebook/re_split.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | s = '111aaa222bbb333' 4 | 5 | print(re.split('[a-z]+', s)) 6 | # ['111', '222', '333'] 7 | 8 | print(re.split('[0-9]+', s)) 9 | # ['', 'aaa', 'bbb', ''] 10 | 11 | print(re.split('[a-z]+', s, 1)) 12 | # ['111', '222bbb333'] 13 | -------------------------------------------------------------------------------- /notebook/test_module.py: -------------------------------------------------------------------------------- 1 | def func(): 2 | print(' This is func() in test_module.py') 3 | print(' __name__ is', __name__) 4 | 5 | 6 | if __name__ == '__main__': 7 | print("Start if __name__ == '__main__'") 8 | print('call func()') 9 | func() 10 | -------------------------------------------------------------------------------- /notebook/doctest_example_verbose.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | ''' 3 | >>> add(1, 2) 4 | 3 5 | >>> add(5, 10) 6 | 15 7 | ''' 8 | 9 | return a + b 10 | 11 | 12 | if __name__ == '__main__': 13 | import doctest 14 | doctest.testmod(verbose=True) 15 | -------------------------------------------------------------------------------- /notebook/name_main_example.py: -------------------------------------------------------------------------------- 1 | import math 2 | import numpy as np 3 | 4 | print(math.__name__) 5 | # math 6 | 7 | print(np.__name__) 8 | # numpy 9 | 10 | import hello 11 | 12 | print(hello.__name__) 13 | # hello 14 | 15 | hello.func() 16 | # Hello! 17 | # __name__ is hello 18 | -------------------------------------------------------------------------------- /notebook/print_list_elements.py: -------------------------------------------------------------------------------- 1 | l = [0, 1, 2] 2 | print(l) 3 | # [0, 1, 2] 4 | 5 | print(*l) # => print(0, 1, 2) 6 | # 0 1 2 7 | 8 | print(*l, sep='') 9 | # 012 10 | 11 | print(*l, sep='-') 12 | # 0-1-2 13 | 14 | s = '-'.join([str(i) for i in l]) 15 | print(s) 16 | # 0-1-2 17 | -------------------------------------------------------------------------------- /notebook/my_package/sub_package2/sub_mod2.py: -------------------------------------------------------------------------------- 1 | from .. import mod1 2 | from ..sub_package1 import sub_mod1 3 | 4 | 5 | def func_parent(): 6 | print('from sub_mod2') 7 | mod1.func() 8 | 9 | 10 | def func_parent_sub(): 11 | print('from sub_mod2') 12 | sub_mod1.func() 13 | -------------------------------------------------------------------------------- /notebook/time_time_usage.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | ut = time.time() 4 | 5 | print(ut) 6 | # 1549281692.9876952 7 | 8 | print(type(ut)) 9 | # 10 | 11 | start = time.time() 12 | 13 | time.sleep(3) 14 | 15 | t = time.time() - start 16 | 17 | print(t) 18 | # 3.001929998397827 19 | -------------------------------------------------------------------------------- /notebook/argparse_type_strtobool.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from setuptools._distutils.util import strtobool 4 | 5 | parser = argparse.ArgumentParser() 6 | parser.add_argument('arg_bool', type=strtobool) 7 | 8 | args = parser.parse_args() 9 | print(args.arg_bool) 10 | print(type(args.arg_bool)) 11 | -------------------------------------------------------------------------------- /notebook/collections_deque_stack.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | d = deque(['a', 'b', 'c']) 4 | print(d) 5 | # deque(['a', 'b', 'c']) 6 | 7 | d.append('d') 8 | print(d) 9 | # deque(['a', 'b', 'c', 'd']) 10 | 11 | print(d.pop()) 12 | # d 13 | 14 | print(d) 15 | # deque(['a', 'b', 'c']) 16 | -------------------------------------------------------------------------------- /notebook/format_error.py: -------------------------------------------------------------------------------- 1 | l = [0, 1] 2 | print(type(l)) 3 | # 4 | 5 | # print('{:*^16}'.format(l)) 6 | # TypeError: unsupported format string passed to list.__format__ 7 | 8 | print(type(str(l))) 9 | # 10 | 11 | print('{:*^16}'.format(str(l))) 12 | # *****[0, 1]***** 13 | -------------------------------------------------------------------------------- /notebook/random_uniform.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print(random.uniform(100, 200)) 4 | # 175.26585048238275 5 | 6 | print(random.uniform(100, -100)) 7 | # -27.82338731501028 8 | 9 | print(random.uniform(100, 100)) 10 | # 100.0 11 | 12 | print(random.uniform(1.234, 5.637)) 13 | # 2.606743596829249 14 | -------------------------------------------------------------------------------- /notebook/requests_url_params.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = 'https://www.google.co.jp/search' 4 | 5 | params = {'q': '日本代表', 'tbm': 'nws'} 6 | 7 | r = requests.get(url, params=params) 8 | 9 | print(r.url) 10 | # https://www.google.co.jp/search?q=%E6%97%A5%E6%9C%AC%E4%BB%A3%E8%A1%A8&tbm=nws 11 | -------------------------------------------------------------------------------- /notebook/collections_deque_queue.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | d = deque(['a', 'b', 'c']) 4 | print(d) 5 | # deque(['a', 'b', 'c']) 6 | 7 | d.append('d') 8 | print(d) 9 | # deque(['a', 'b', 'c', 'd']) 10 | 11 | print(d.popleft()) 12 | # a 13 | 14 | print(d) 15 | # deque(['b', 'c', 'd']) 16 | -------------------------------------------------------------------------------- /notebook/positive_negative_zero.py: -------------------------------------------------------------------------------- 1 | print(0) 2 | # 0 3 | 4 | print(-0) 5 | # 0 6 | 7 | print(0 == -0) 8 | # True 9 | 10 | print(0 is -0) 11 | # True 12 | 13 | print(0.0) 14 | # 0.0 15 | 16 | print(-0.0) 17 | # -0.0 18 | 19 | print(0.0 == -0.0) 20 | # True 21 | 22 | print(0.0 is -0.0) 23 | # False 24 | -------------------------------------------------------------------------------- /notebook/sklearn_load_data_import.py: -------------------------------------------------------------------------------- 1 | import sklearn.datasets 2 | 3 | data_iris = sklearn.datasets.load_iris() 4 | 5 | print(type(data_iris)) 6 | # 7 | 8 | data_boston = sklearn.datasets.load_boston() 9 | 10 | print(type(data_boston)) 11 | # 12 | -------------------------------------------------------------------------------- /notebook/import_example_as.py: -------------------------------------------------------------------------------- 1 | import math as m 2 | 3 | print(m.pi) 4 | # 3.141592653589793 5 | 6 | # print(math.pi) 7 | # NameError: name 'math' is not defined 8 | 9 | from math import pi as PI 10 | 11 | print(PI) 12 | # 3.141592653589793 13 | 14 | # print(pi) 15 | # NameError: name 'pi' is not defined 16 | -------------------------------------------------------------------------------- /notebook/pass_continue.py: -------------------------------------------------------------------------------- 1 | for i in range(3): 2 | print(i) 3 | if i == 1: 4 | continue 5 | print('CONTINUE') 6 | # 0 7 | # 1 8 | # 2 9 | 10 | for i in range(3): 11 | print(i) 12 | if i == 1: 13 | pass 14 | print('PASS') 15 | # 0 16 | # 1 17 | # PASS 18 | # 2 19 | -------------------------------------------------------------------------------- /notebook/data/src/sample_date.csv: -------------------------------------------------------------------------------- 1 | date,val_1,val_2 2 | 2017-11-01,65,76 3 | 2017-11-07,26,66 4 | 2017-11-18,47,47 5 | 2017-11-27,20,38 6 | 2017-12-05,65,85 7 | 2017-12-12,4,29 8 | 2017-12-22,31,54 9 | 2017-12-29,21,8 10 | 2018-01-03,98,76 11 | 2018-01-08,48,64 12 | 2018-01-19,18,48 13 | 2018-01-23,86,70 -------------------------------------------------------------------------------- /notebook/math_perm.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.perm(4, 2)) 4 | # 12 5 | 6 | print(math.perm(4, 4)) 7 | # 24 8 | 9 | # print(math.perm(4.5, 2.5)) 10 | # TypeError: 'float' object cannot be interpreted as an integer 11 | 12 | # print(math.perm(-4, -2)) 13 | # ValueError: n must be a non-negative integer 14 | -------------------------------------------------------------------------------- /notebook/my_package/mod2.py: -------------------------------------------------------------------------------- 1 | from . import mod1 2 | from .sub_package1 import sub_mod1 3 | 4 | 5 | def func_same(): 6 | print('from mod2') 7 | mod1.func() 8 | 9 | 10 | def func_sub(): 11 | print('from mod2') 12 | sub_mod1.func() 13 | 14 | 15 | if __name__ == '__main__': 16 | func_sub() 17 | -------------------------------------------------------------------------------- /notebook/numpy_roll_image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | img = np.array(Image.open('data/src/lena.jpg')) 5 | 6 | print(img.shape) 7 | # (225, 400, 3) 8 | 9 | img_scroll = np.roll(img, (50, 100), axis=(0, 1)) 10 | 11 | Image.fromarray(img_scroll).save('data/dst/lena_numpy_roll.jpg') 12 | -------------------------------------------------------------------------------- /notebook/data/src/sample_date_jp.csv: -------------------------------------------------------------------------------- 1 | date,val_1,val_2 2 | 2017年11月1日,65,76 3 | 2017年11月7日,26,66 4 | 2017年11月18日,47,47 5 | 2017年11月27日,20,38 6 | 2017年12月5日,65,85 7 | 2017年12月12日,4,29 8 | 2017年12月22日,31,54 9 | 2017年12月29日,21,8 10 | 2018年1月3日,98,76 11 | 2018年1月8日,48,64 12 | 2018年1月19日,18,48 13 | 2018年1月23日,86,70 -------------------------------------------------------------------------------- /notebook/requests_request_header.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | url = 'https://www.yahoo.co.jp/' 4 | 5 | ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' 6 | 7 | headers = {'User-Agent': ua} 8 | 9 | r_ua = requests.get(url, headers=headers) 10 | -------------------------------------------------------------------------------- /notebook/doctest_example_without_import.py: -------------------------------------------------------------------------------- 1 | def add(a, b): 2 | ''' 3 | >>> add(1, 2) 4 | 3 5 | >>> add(5, 10) 6 | 15 7 | ''' 8 | 9 | return a + b 10 | 11 | 12 | if __name__ == '__main__': 13 | import sys 14 | result = add(int(sys.argv[1]), int(sys.argv[2])) 15 | print(result) 16 | -------------------------------------------------------------------------------- /notebook/short_circuit.py: -------------------------------------------------------------------------------- 1 | def test(): 2 | print('function is called') 3 | return True 4 | 5 | print(True and test()) 6 | # function is called 7 | # True 8 | 9 | print(False and test()) 10 | # False 11 | 12 | print(True or test()) 13 | # True 14 | 15 | print(False or test()) 16 | # function is called 17 | # True 18 | -------------------------------------------------------------------------------- /notebook/platform_python_version.py: -------------------------------------------------------------------------------- 1 | import platform 2 | 3 | print(platform.python_version()) 4 | # 3.11.3 5 | 6 | print(type(platform.python_version())) 7 | # 8 | 9 | print(platform.python_version_tuple()) 10 | # ('3', '11', '3') 11 | 12 | print(type(platform.python_version_tuple())) 13 | # 14 | -------------------------------------------------------------------------------- /notebook/typing_example.py: -------------------------------------------------------------------------------- 1 | from typing import Union, Any 2 | 3 | def func_union(x: Union[int, float]) -> float: 4 | return x * 0.5 5 | 6 | var: Any = 100 7 | 8 | def func(x: int | float) -> float: 9 | return x * 0.5 10 | 11 | i: int = 100 12 | l: list[float] = [0.1, 0.2, 0.3] 13 | d: dict[str, int] = {'a': 100, 'b': 200} 14 | -------------------------------------------------------------------------------- /notebook/seaborn_iris.py: -------------------------------------------------------------------------------- 1 | import seaborn as sns 2 | 3 | sns.set(style="ticks") 4 | 5 | df = sns.load_dataset("iris") 6 | 7 | # http://seaborn.pydata.org/generated/seaborn.pairplot.html 8 | sns.pairplot(df, hue='species', markers=["o", "s", "+"]).savefig('data/dst/seaborn_iris.png') 9 | 10 | # ![seaborn_iris](data/dst/seaborn_iris.png) 11 | -------------------------------------------------------------------------------- /notebook/pass_def_class.py: -------------------------------------------------------------------------------- 1 | # def empty_func(): 2 | # SyntaxError: unexpected EOF while parsing 3 | 4 | def empty_func(): 5 | pass 6 | 7 | # class EmptyClass(): 8 | # SyntaxError: unexpected EOF while parsing 9 | 10 | class EmptyClass(): 11 | pass 12 | 13 | def empty_func_one_line(): pass 14 | 15 | class EmptyClassOneLine(): pass 16 | -------------------------------------------------------------------------------- /notebook/int_bit_count_timeit.py: -------------------------------------------------------------------------------- 1 | def bit_count(self): 2 | return bin(self).count("1") 3 | 4 | i = 255 5 | 6 | %%timeit 7 | i.bit_count() 8 | # 22 ns ± 0.072 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) 9 | 10 | %%timeit 11 | bit_count(i) 12 | # 121 ns ± 0.275 ns per loop (mean ± std. dev. of 7 runs, 10,000,000 loops each) 13 | -------------------------------------------------------------------------------- /notebook/numpy_image_declease_color.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | im = np.array(Image.open('data/src/lena_square.png').resize((256, 256))) 5 | 6 | im_32 = im // 32 * 32 7 | im_128 = im // 128 * 128 8 | 9 | im_dec = np.concatenate((im, im_32, im_128), axis=1) 10 | 11 | Image.fromarray(im_dec).save('data/dst/lena_numpy_dec_color.png') 12 | -------------------------------------------------------------------------------- /notebook/empty_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | 4 | os.makedirs('temp/dir/', exist_ok=True) 5 | 6 | with open('file.txt', 'w') as f: 7 | f.write('') 8 | 9 | print(os.listdir('temp/')) 10 | # ['dir', 'test.txt'] 11 | 12 | target_dir = 'temp' 13 | 14 | shutil.rmtree(target_dir) 15 | os.mkdir(target_dir) 16 | 17 | print(os.listdir('temp/')) 18 | # [] 19 | -------------------------------------------------------------------------------- /notebook/numpy_tile_image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | img = np.array(Image.open('data/src/lena_square.png').resize((128, 128))) 5 | 6 | print(img.shape) 7 | # (128, 128, 3) 8 | 9 | img_tile = np.tile(img, (2, 3, 1)) 10 | 11 | print(img_tile.shape) 12 | # (256, 384, 3) 13 | 14 | Image.fromarray(img_tile).save('data/dst/lena_numpy_tile.jpg') 15 | -------------------------------------------------------------------------------- /notebook/pandas_read_clipboard.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.read_clipboard() 4 | print(df) 5 | # バージョン リリース日[16] 6 | # 0 3.0 2008年12月3日 7 | # 1 3.1 2009年6月27日 8 | # 2 3.2 2011年2月20日 9 | # 3 3.3 2012年9月29日 10 | # 4 3.4 2014年3月16日 11 | # 5 3.5 2015年9月13日 12 | # 6 3.6 2016年12月23日 13 | 14 | df.to_csv('data/dst/test.csv') 15 | -------------------------------------------------------------------------------- /notebook/random_random.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print(random.random()) 4 | # 0.4496839011176701 5 | 6 | random.seed(0) 7 | print(random.random()) 8 | # 0.8444218515250481 9 | 10 | print(random.random()) 11 | # 0.7579544029403025 12 | 13 | random.seed(0) 14 | print(random.random()) 15 | # 0.8444218515250481 16 | 17 | print(random.random()) 18 | # 0.7579544029403025 19 | -------------------------------------------------------------------------------- /notebook/matplotlib_example_single.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | x = np.linspace(0, 2.0, 20) 5 | 6 | plt.plot(x, x, 'b:') 7 | plt.plot(x, x**1.5, 'rs-') 8 | plt.plot(x, x**2, color='#30F050', marker='^', markerfacecolor='blue', markeredgecolor='blue') 9 | 10 | plt.tight_layout() 11 | 12 | plt.savefig("data/dst/matplotlib_example_single.png") 13 | -------------------------------------------------------------------------------- /notebook/os_remove.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | os.makedirs('temp/', exist_ok=True) 4 | 5 | with open('temp/file.txt', 'w') as f: 6 | f.write('') 7 | 8 | print(os.listdir('temp')) 9 | # ['file.txt'] 10 | 11 | os.remove('temp/file.txt') 12 | 13 | print(os.listdir('temp')) 14 | # [] 15 | 16 | # os.remove('temp/') 17 | # PermissionError: [Errno 1] Operation not permitted: 'temp/' 18 | -------------------------------------------------------------------------------- /notebook/pillow_add_margin.py: -------------------------------------------------------------------------------- 1 | from my_lib.imagelib import add_margin 2 | 3 | from PIL import Image 4 | 5 | im = Image.open('data/src/astronaut_rect.bmp') 6 | 7 | # ![](data/src/astronaut_rect.bmp) 8 | 9 | im_new = add_margin(im, 50, 10, 0, 100, (128, 0, 64)) 10 | im_new.save('data/dst/astronaut_add_margin.jpg', quality=95) 11 | 12 | # ![](data/dst/astronaut_add_margin.jpg) 13 | -------------------------------------------------------------------------------- /notebook/combinations_count.py: -------------------------------------------------------------------------------- 1 | from operator import mul 2 | from functools import reduce 3 | 4 | def combinations_count(n, r): 5 | r = min(r, n - r) 6 | numer = reduce(mul, range(n, n - r, -1), 1) 7 | denom = reduce(mul, range(1, r + 1), 1) 8 | return numer // denom 9 | 10 | print(combinations_count(4, 2)) 11 | # 6 12 | 13 | print(combinations_count(4, 0)) 14 | # 1 15 | -------------------------------------------------------------------------------- /notebook/data/src/sample_multi.csv: -------------------------------------------------------------------------------- 1 | level_1,level_2,level_3,val_1,val_2 2 | A0,B0,C0,98,90 3 | A0,B0,C1,44,9 4 | A0,B1,C2,39,17 5 | A0,B1,C3,75,71 6 | A1,B2,C0,1,89 7 | A1,B2,C1,54,60 8 | A1,B3,C2,47,6 9 | A1,B3,C3,16,5 10 | A2,B0,C0,75,22 11 | A2,B0,C1,19,4 12 | A2,B1,C2,25,52 13 | A2,B1,C3,57,40 14 | A3,B2,C0,64,54 15 | A3,B2,C1,27,96 16 | A3,B3,C2,100,77 17 | A3,B3,C3,22,50 -------------------------------------------------------------------------------- /notebook/opencv_videocapture_camera.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap_cam = cv2.VideoCapture(0) 4 | print(type(cap_cam)) 5 | # 6 | 7 | print(cap_cam.isOpened()) 8 | # True 9 | 10 | cap_cam_wrong = cv2.VideoCapture(1) 11 | print(type(cap_cam_wrong)) 12 | # 13 | 14 | print(cap_cam_wrong.isOpened()) 15 | # False 16 | 17 | cap_cam.release() 18 | -------------------------------------------------------------------------------- /notebook/data/dst/pandas_read_html_sample.csv: -------------------------------------------------------------------------------- 1 | ,バージョン,リリース日[17] 2 | 0,2.0,2000年10月16日 3 | 2,2.2,2001年12月21日 4 | 1,2.1,2001年4月15日 5 | 3,2.3,2003年7月29日 6 | 4,2.4,2004年11月30日 7 | 5,2.5,2006年9月19日 8 | 6,2.6,2008年10月1日 9 | 8,3.0,2008年12月3日 10 | 9,3.1,2009年6月27日 11 | 7,2.7,2010年7月4日 12 | 10,3.2,2011年2月20日 13 | 11,3.3,2012年9月29日 14 | 12,3.4,2014年3月16日 15 | 13,3.5,2015年9月13日 16 | 14,3.6,2016年12月23日 17 | -------------------------------------------------------------------------------- /notebook/numpy_image_gamma.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import numpy as np 3 | 4 | im = np.array(Image.open('data/src/lena_square.png')) 5 | 6 | im_1_22 = 255.0 * (im / 255.0)**(1 / 2.2) 7 | im_22 = 255.0 * (im / 255.0)**2.2 8 | 9 | im_gamma = np.concatenate((im_1_22, im, im_22), axis=1) 10 | 11 | pil_img = Image.fromarray(np.uint8(im_gamma)) 12 | pil_img.save('data/dst/lena_numpy_gamma.jpg') 13 | -------------------------------------------------------------------------------- /notebook/numpy_list_to_ndarray.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | l = [[0, 0, 0], [0, 0, 0]] 4 | arr = np.array(l) 5 | print(arr) 6 | # [[0 0 0] 7 | # [0 0 0]] 8 | 9 | print(arr.dtype, arr.shape, arr.ndim) 10 | # int64 (2, 3) 2 11 | 12 | l2 = [[0, 0, 0], [0, 0]] 13 | arr2 = np.array(l2) 14 | print(arr2) 15 | # [[0, 0, 0] [0, 0]] 16 | 17 | print(arr2.dtype, arr2.shape, arr2.ndim) 18 | # object (2,) 1 19 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_file.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap_file = cv2.VideoCapture('data/temp/sample_video.mp4') 4 | print(type(cap_file)) 5 | # 6 | 7 | print(cap_file.isOpened()) 8 | # True 9 | 10 | cap_file_wrong = cv2.VideoCapture('wrong_path') 11 | print(type(cap_file_wrong)) 12 | # 13 | 14 | print(cap_file_wrong.isOpened()) 15 | # False 16 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_prop_fps.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap = cv2.VideoCapture(0) 4 | 5 | print(cap.get(cv2.CAP_PROP_FPS)) 6 | # 29.000049 7 | 8 | print(cap.set(cv2.CAP_PROP_FPS, 10)) 9 | # True 10 | 11 | print(cap.get(cv2.CAP_PROP_FPS)) 12 | # 10.0 13 | 14 | print(cap.set(cv2.CAP_PROP_FPS, 120)) 15 | # True 16 | 17 | print(cap.get(cv2.CAP_PROP_FPS)) 18 | # 30.00003 19 | 20 | cap.release() 21 | -------------------------------------------------------------------------------- /notebook/re_greedy.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | s = 'aaa@xxx.com bbb@yyy.com' 4 | 5 | m = re.match(r'.+com', s) 6 | print(m) 7 | # 8 | 9 | print(m.group()) 10 | # aaa@xxx.com bbb@yyy.com 11 | 12 | m = re.match(r'.+?com', s) 13 | print(m) 14 | # 15 | 16 | print(m.group()) 17 | # aaa@xxx.com 18 | -------------------------------------------------------------------------------- /notebook/datetime_timezone_str.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | s = '2022/12/31 05:00:30+0900' 4 | 5 | dt = datetime.datetime.strptime(s, '%Y/%m/%d %H:%M:%S%z') 6 | print(dt) 7 | # 2022-12-31 05:00:30+09:00 8 | 9 | print(dt.tzinfo) 10 | # UTC+09:00 11 | 12 | s = '2022-12-31T05:00:30+09:00' 13 | 14 | dt = datetime.datetime.fromisoformat(s) 15 | print(dt) 16 | # 2022-12-31 05:00:30+09:00 17 | 18 | print(dt.tzinfo) 19 | # UTC+09:00 20 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_play_cam.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import sys 3 | 4 | camera_id = 0 5 | delay = 1 6 | window_name = 'frame' 7 | 8 | cap = cv2.VideoCapture(camera_id) 9 | 10 | if not cap.isOpened(): 11 | sys.exit() 12 | 13 | while True: 14 | ret, frame = cap.read() 15 | cv2.imshow(window_name, frame) 16 | if cv2.waitKey(delay) & 0xFF == ord('q'): 17 | break 18 | 19 | cv2.destroyWindow(window_name) 20 | -------------------------------------------------------------------------------- /notebook/import_example_relative.py: -------------------------------------------------------------------------------- 1 | from my_package import mod2 2 | from my_package.sub_package2 import sub_mod2 3 | 4 | mod2.func_same() 5 | # from mod2 6 | # -- mod1.func is called 7 | 8 | mod2.func_sub() 9 | # from mod2 10 | # -- sub_mod1.func1 is called 11 | 12 | sub_mod2.func_parent() 13 | # from sub_mod2 14 | # -- mod1.func is called 15 | 16 | sub_mod2.func_parent_sub() 17 | # from sub_mod2 18 | # -- sub_mod1.func1 is called 19 | -------------------------------------------------------------------------------- /notebook/math_comb.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.comb(4, 2)) 4 | # 6 5 | 6 | # print(math.comb(4.5, 2.5)) 7 | # TypeError: 'float' object cannot be interpreted as an integer 8 | 9 | # print(math.comb(-4, -2)) 10 | # ValueError: n must be a non-negative integer 11 | 12 | def combinations_with_replacement_count(n, k): 13 | return math.comb(n + k - 1, k) 14 | 15 | print(combinations_with_replacement_count(4, 2)) 16 | # 10 17 | -------------------------------------------------------------------------------- /notebook/random_list.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print([random.random() for i in range(5)]) 4 | # [0.5518201298350598, 0.3476911314933616, 0.8463426180468342, 0.8949046353303931, 0.40822657702632625] 5 | 6 | print([random.randint(0, 10) for i in range(5)]) 7 | # [8, 5, 7, 10, 7] 8 | 9 | print(random.sample(range(10), k=5)) 10 | # [6, 4, 3, 7, 5] 11 | 12 | print(random.sample(range(100, 200, 10), k=5)) 13 | # [130, 190, 140, 150, 170] 14 | -------------------------------------------------------------------------------- /notebook/sklearn_fetch_olivetti_faces.py: -------------------------------------------------------------------------------- 1 | from sklearn.datasets import fetch_olivetti_faces 2 | 3 | data = fetch_olivetti_faces() 4 | 5 | print(type(data)) 6 | # 7 | 8 | print(data.keys()) 9 | # dict_keys(['data', 'images', 'target', 'DESCR']) 10 | 11 | print(data.data.shape) 12 | # (400, 4096) 13 | 14 | print(data.target.shape) 15 | # (400,) 16 | 17 | print(data.images.shape) 18 | # (400, 64, 64) 19 | -------------------------------------------------------------------------------- /notebook/tensorflow_constant.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | 3 | const1 = tf.constant(5) 4 | const2 = tf.constant(10) 5 | 6 | print(const1) 7 | print(const2) 8 | # Tensor("Const:0", shape=(), dtype=int32) 9 | # Tensor("Const_1:0", shape=(), dtype=int32) 10 | 11 | with tf.Session() as sess: 12 | const1_result, const2_result = sess.run([const1, const2]) 13 | print(const1_result) 14 | print(const2_result) 15 | # 5 16 | # 10 17 | -------------------------------------------------------------------------------- /notebook/array_example.py: -------------------------------------------------------------------------------- 1 | import array 2 | 3 | arr_int = array.array('i', [0, 1, 2]) 4 | print(arr_int) 5 | # array('i', [0, 1, 2]) 6 | 7 | arr_float = array.array('f', [0.0, 0.25, 0.5]) 8 | print(arr_float) 9 | # array('f', [0.0, 0.25, 0.5]) 10 | 11 | # arr_int = array.array('i', [0, 0.5, 1]) 12 | # TypeError: 'float' object cannot be interpreted as an integer 13 | 14 | print(arr_int[1]) 15 | # 1 16 | 17 | print(sum(arr_int)) 18 | # 3 19 | -------------------------------------------------------------------------------- /notebook/os_getcwd_chdir.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | path = os.getcwd() 4 | 5 | print(path) 6 | # /Users/mbp/Documents/my-project/python-snippets/notebook 7 | 8 | print(type(path)) 9 | # 10 | 11 | os.chdir('..') 12 | 13 | print(os.getcwd()) 14 | # /Users/mbp/Documents/my-project/python-snippets 15 | 16 | os.chdir('notebook/data') 17 | 18 | print(os.getcwd()) 19 | # /Users/mbp/Documents/my-project/python-snippets/notebook/data 20 | -------------------------------------------------------------------------------- /notebook/pypdf_split.py: -------------------------------------------------------------------------------- 1 | import pypdf 2 | 3 | print(pypdf.__version__) 4 | # 5.5.0 5 | 6 | writer = pypdf.PdfWriter() 7 | writer.append('data/src/pdf/sample1.pdf', pages=pypdf.PageRange(':2')) 8 | writer.write('data/temp/sample_split1.pdf') 9 | 10 | writer = pypdf.PdfWriter() 11 | writer.append('data/src/pdf/sample1.pdf', pages=pypdf.PageRange('2:')) 12 | writer.write('data/temp/sample_split2.pdf') 13 | # (True, <_io.FileIO [closed]>) 14 | -------------------------------------------------------------------------------- /notebook/pypdf_split_pages.py: -------------------------------------------------------------------------------- 1 | import pypdf 2 | 3 | print(pypdf.__version__) 4 | # 5.5.0 5 | 6 | def split_pdf_pages(src_path, dst_basepath): 7 | src_pdf = pypdf.PdfReader(src_path) 8 | for i, page in enumerate(src_pdf.pages): 9 | dst_pdf = pypdf.PdfWriter() 10 | dst_pdf.add_page(page) 11 | dst_pdf.write(f'{dst_basepath}_{i}.pdf') 12 | 13 | split_pdf_pages('data/src/pdf/sample1.pdf', 'data/temp/sample1') 14 | -------------------------------------------------------------------------------- /notebook/random_choice.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | l = [0, 1, 2, 3, 4] 4 | 5 | print(random.choice(l)) 6 | # 1 7 | 8 | print(random.choice(('xxx', 'yyy', 'zzz'))) 9 | # yyy 10 | 11 | print(random.choice('abcde')) 12 | # b 13 | 14 | # print(random.choice([])) 15 | # IndexError: Cannot choose from an empty sequence 16 | 17 | random.seed(0) 18 | print(random.choice(l)) 19 | # 3 20 | 21 | random.seed(0) 22 | print(random.choice(l)) 23 | # 3 24 | -------------------------------------------------------------------------------- /notebook/sys_exit_sh.log: -------------------------------------------------------------------------------- 1 | $ python sys_exit.py 2 | Start 3 | 4 | $ python sys_exit_if.py 5 | Start 6 | Continue 7 | 8 | $ python sys_exit_stderr.py 9 | Error message 10 | 11 | $ python sys_exit_stderr.py 1> data/temp/stdout.txt 2> data/temp/stderr.txt 12 | 13 | $ cat data/temp/stdout.txt 14 | 15 | $ cat data/temp/stderr.txt 16 | Error message 17 | 18 | $ python sys_exit_systemexit.py 19 | Start 20 | Catch all exceptions 21 | Finish 22 | -------------------------------------------------------------------------------- /notebook/builtins_module.py: -------------------------------------------------------------------------------- 1 | import builtins 2 | 3 | print(len('abc')) 4 | # 3 5 | 6 | print(builtins.len('abc')) 7 | # 3 8 | 9 | print(len) 10 | # 11 | 12 | print(builtins.len) 13 | # 14 | 15 | print(builtins.len is len) 16 | # True 17 | 18 | print(__builtins__.len('abc')) 19 | # 3 20 | 21 | print(__builtins__.len is len) 22 | # True 23 | 24 | print(__builtins__ is builtins) 25 | # True 26 | -------------------------------------------------------------------------------- /notebook/int_truncate.py: -------------------------------------------------------------------------------- 1 | print(int(10.123)) 2 | # 10 3 | 4 | print(int(10.987)) 5 | # 10 6 | 7 | print(int(10)) 8 | # 10 9 | 10 | print(type(int(10.123))) 11 | # 12 | 13 | print(int(-10.123)) 14 | # -10 15 | 16 | print(int(-10.987)) 17 | # -10 18 | 19 | print(int('10')) 20 | # 10 21 | 22 | # print(int('10.123')) 23 | # ValueError: invalid literal for int() with base 10: '10.123' 24 | 25 | print(int('FF', 16)) 26 | # 255 27 | -------------------------------------------------------------------------------- /notebook/pillow_expand_to_square.py: -------------------------------------------------------------------------------- 1 | from my_lib.imagelib import expand2square 2 | 3 | from PIL import Image 4 | 5 | im = Image.open('data/src/astronaut_rect.bmp') 6 | 7 | # ![](data/src/astronaut_rect.bmp) 8 | 9 | im_new = expand2square(im, (0, 0, 0)) 10 | im_new.save('data/dst/astronaut_expand_square.jpg', quality=95) 11 | 12 | # ![](data/dst/astronaut_expand_square.jpg) 13 | 14 | im_new = expand2square(im, (0, 0, 0)).resize((150, 150)) 15 | -------------------------------------------------------------------------------- /notebook/opencv_bitwise_and.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | src1 = cv2.imread('data/src/lena.jpg') 4 | 5 | src2 = cv2.imread('data/src/horse_r.png') 6 | 7 | src2 = cv2.resize(src2, src1.shape[1::-1]) 8 | 9 | print(src2.shape) 10 | # (225, 400, 3) 11 | 12 | print(src2.dtype) 13 | # uint8 14 | 15 | dst = cv2.bitwise_and(src1, src2) 16 | 17 | cv2.imwrite('data/dst/opencv_bitwise_and.jpg', dst) 18 | # True 19 | 20 | # ![](data/dst/opencv_bitwise_and.jpg) 21 | -------------------------------------------------------------------------------- /notebook/random_randrange_randint.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | print(list(range(10))) 4 | # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 5 | 6 | print(random.randrange(10)) 7 | # 5 8 | 9 | print(list(range(10, 20, 2))) 10 | # [10, 12, 14, 16, 18] 11 | 12 | print(random.randrange(10, 20, 2)) 13 | # 18 14 | 15 | print(random.randint(50, 100)) 16 | # print(random.randrange(50, 101)) 17 | # 74 18 | 19 | random.seed(0) 20 | print(random.randint(50, 100)) 21 | # 74 22 | -------------------------------------------------------------------------------- /notebook/arxiv_download.py: -------------------------------------------------------------------------------- 1 | import arxiv 2 | import time 3 | 4 | l = arxiv.query(query='au:"Grisha Perelman"') 5 | 6 | arxiv.download(l[0], 'data/temp/') 7 | # 'data/temp/0211159v1.The_entropy_formula_for_the_Ricci_flow_and_its_geometric_applications.pdf' 8 | 9 | arxiv.download(l[0], 'data/temp/', lambda x: x.get('id').split('/')[-1]) 10 | # 'data/temp/0211159v1.pdf' 11 | 12 | for a in l: 13 | arxiv.download(a, 'data/temp/') 14 | time.sleep(10) 15 | -------------------------------------------------------------------------------- /notebook/import_example_relative_other.py: -------------------------------------------------------------------------------- 1 | from my_package.mod2 import func_same, func_sub 2 | from my_package.sub_package2.sub_mod2 import func_parent, func_parent_sub 3 | 4 | func_same() 5 | # from mod2 6 | # -- mod1.func is called 7 | 8 | func_sub() 9 | # from mod2 10 | # -- sub_mod1.func1 is called 11 | 12 | func_parent() 13 | # from sub_mod2 14 | # -- mod1.func is called 15 | 16 | func_parent_sub() 17 | # from sub_mod2 18 | # -- sub_mod1.func1 is called 19 | -------------------------------------------------------------------------------- /notebook/numpy_rint.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.1 5 | 6 | a = np.array([12.3, 45.6, 78.9]) 7 | 8 | print(np.rint(a)) 9 | # [12. 46. 79.] 10 | 11 | l = [12.3, 45.6, 78.9] 12 | 13 | print(np.rint(l)) 14 | # [12. 46. 79.] 15 | 16 | print(np.rint(12.3)) 17 | # 12.0 18 | 19 | print(np.rint(a).dtype) 20 | # float64 21 | 22 | print(np.rint([-3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5])) 23 | # [-4. -2. -2. -0. 0. 2. 2. 4.] 24 | -------------------------------------------------------------------------------- /notebook/opencv_psnr.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img_org = cv2.imread('data/src/lena.jpg') 4 | img_q95 = cv2.imread('data/src/lena_q95.jpg') 5 | img_q50 = cv2.imread('data/src/lena_q50.jpg') 6 | 7 | print(cv2.PSNR(img_org, img_q95)) 8 | # 39.02455758374567 9 | 10 | print(cv2.PSNR(img_org, img_q50)) 11 | # 30.34829234238757 12 | 13 | print(cv2.PSNR(img_org, img_org)) 14 | # 361.20199909921956 15 | 16 | print(cv2.PSNR(img_org, img_q95, R=255)) 17 | # 39.02455758374567 18 | -------------------------------------------------------------------------------- /notebook/pandas_to_clipboard.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.DataFrame({'a': [0, 1, 2], 'b': [3, 4, 5]}) 4 | print(df) 5 | # a b 6 | # 0 0 3 7 | # 1 1 4 8 | # 2 2 5 9 | 10 | df.to_clipboard() 11 | 12 | # a b 13 | # 0 0 3 14 | # 1 1 4 15 | # 2 2 5 16 | 17 | df.to_clipboard(excel=False) 18 | 19 | # a b 20 | # 0 0 3 21 | # 1 1 4 22 | # 2 2 5 23 | 24 | df.to_clipboard(sep=',') 25 | 26 | # ,a,b 27 | # 0,0,3 28 | # 1,1,4 29 | # 2,2,5 30 | -------------------------------------------------------------------------------- /notebook/print_len_eafp.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | def print_len_eafp(x): 4 | try: 5 | print(len(x)) 6 | except TypeError as e: 7 | print(e) 8 | 9 | print_len_eafp([0, 1, 2]) 10 | # 3 11 | 12 | print_len_eafp(100) 13 | # object of type 'int' has no len() 14 | 15 | print_len_eafp((0, 1, 2)) 16 | # 3 17 | 18 | print_len_eafp('abc') 19 | # 3 20 | 21 | a = np.arange(3) 22 | print(a) 23 | # [0 1 2] 24 | 25 | print_len_eafp(a) 26 | # 3 27 | -------------------------------------------------------------------------------- /notebook/all_example.py: -------------------------------------------------------------------------------- 1 | print(all([True, True, True])) 2 | # True 3 | 4 | print(all([True, False, True])) 5 | # False 6 | 7 | print(all((True, True, True))) 8 | # True 9 | 10 | print(all({True, True, True})) 11 | # True 12 | 13 | print(all(['aaa', 'bbb', 'ccc'])) 14 | # True 15 | 16 | print(all(['aaa', 'bbb', 'ccc', ''])) 17 | # False 18 | 19 | print(all([1, 2, 3])) 20 | # True 21 | 22 | print(all([0, 1, 2, 3])) 23 | # False 24 | 25 | print(all([])) 26 | # True 27 | -------------------------------------------------------------------------------- /notebook/numpy_flip_image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | img = np.array(Image.open('data/src/lena.jpg')) 5 | print(type(img)) 6 | # 7 | 8 | print(img.shape) 9 | # (225, 400, 3) 10 | 11 | Image.fromarray(np.flipud(img)).save('data/dst/lena_np_flipud.jpg') 12 | 13 | Image.fromarray(np.fliplr(img)).save('data/dst/lena_np_fliplr.jpg') 14 | 15 | Image.fromarray(np.flip(img, (0, 1))).save('data/dst/lena_np_flip_ud_lr.jpg') 16 | -------------------------------------------------------------------------------- /notebook/numpy_rot90_image.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | img = np.array(Image.open('data/src/lena.jpg')) 5 | print(type(img)) 6 | # 7 | 8 | print(img.shape) 9 | # (225, 400, 3) 10 | 11 | Image.fromarray(np.rot90(img)).save('data/dst/lena_np_rot90.jpg') 12 | 13 | Image.fromarray(np.rot90(img, 2)).save('data/dst/lena_np_rot90_180.jpg') 14 | 15 | Image.fromarray(np.rot90(img, 3)).save('data/dst/lena_np_rot90_270.jpg') 16 | -------------------------------------------------------------------------------- /notebook/pillow_imagegrab_grabclipboard.py: -------------------------------------------------------------------------------- 1 | from PIL import ImageGrab, Image 2 | 3 | img = ImageGrab.grabclipboard() 4 | print(img) 5 | # 6 | 7 | print(isinstance(img, Image.Image)) 8 | # True 9 | 10 | print(img.size) 11 | # (200, 71) 12 | 13 | print(img.mode) 14 | # RGB 15 | 16 | img.save('data/temp/clipboard_image.jpg') 17 | 18 | img = ImageGrab.grabclipboard() 19 | print(img) 20 | # None 21 | -------------------------------------------------------------------------------- /notebook/str_re_split.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | s_nums = 'one1two22three333four' 4 | print(re.split(r'\d+', s_nums)) 5 | # ['one', 'two', 'three', 'four'] 6 | 7 | print(re.split(r'\d+', s_nums, 2)) 8 | # ['one', 'two', 'three333four'] 9 | 10 | s_marks = 'one-two+three#four' 11 | print(re.split('[-+#]', s_marks)) 12 | # ['one', 'two', 'three', 'four'] 13 | 14 | s_strs = 'oneXXXtwoYYYthreeZZZfour' 15 | print(re.split('XXX|YYY|ZZZ', s_strs)) 16 | # ['one', 'two', 'three', 'four'] 17 | -------------------------------------------------------------------------------- /notebook/jupyter_precision.py: -------------------------------------------------------------------------------- 1 | f = 123.456789 2 | 3 | f 4 | # 123.456789 5 | 6 | %precision 3 7 | # '%.3f' 8 | 9 | f 10 | # 123.457 11 | 12 | print(f) 13 | # 123.456789 14 | 15 | %precision 0 16 | # '%.0f' 17 | 18 | 0.4 19 | # 0 20 | 21 | 0.5 22 | # 0 23 | 24 | 0.6 25 | # 1 26 | 27 | %precision %.4e 28 | # '%.4e' 29 | 30 | f 31 | # 1.2346e+02 32 | 33 | %precision %08.2f 34 | # '%08.2f' 35 | 36 | f 37 | # 00123.46 38 | 39 | %precision 40 | # '%r' 41 | 42 | f 43 | # 123.456789 44 | -------------------------------------------------------------------------------- /notebook/numpy_broadcast_to.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.arange(3) 4 | print(a) 5 | # [0 1 2] 6 | 7 | print(a.shape) 8 | # (3,) 9 | 10 | print(np.broadcast_to(a, (3, 3))) 11 | # [[0 1 2] 12 | # [0 1 2] 13 | # [0 1 2]] 14 | 15 | print(type(np.broadcast_to(a, (3, 3)))) 16 | # 17 | 18 | # print(np.broadcast_to(a, (2, 2))) 19 | # ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (3,) and requested shape (2,2) 20 | -------------------------------------------------------------------------------- /notebook/pillow_image_resize.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | img = Image.open('data/src/lena_square.png') 4 | 5 | img_resize = img.resize((256, 256)) 6 | img_resize.save('data/dst/lena_pillow_resize_nearest.jpg') 7 | 8 | img_resize_lanczos = img.resize((256, 256), Image.LANCZOS) 9 | img_resize_lanczos.save('data/dst/lena_pillow_resize_lanczos.jpg') 10 | 11 | img_resize = img.resize((img.width // 2, img.height // 2)) 12 | img_resize_lanczos.save('data/dst/lena_pillow_resize_half.jpg') 13 | -------------------------------------------------------------------------------- /notebook/dir_import_test/main_base.py: -------------------------------------------------------------------------------- 1 | import mod1 2 | 3 | mod1.func() 4 | # -- mod1.func is called 5 | 6 | from mod1 import func 7 | 8 | func() 9 | # -- mod1.func is called 10 | 11 | import dir_for_mod.mod2 12 | 13 | dir_for_mod.mod2.func() 14 | # -- dir_for_mod.mod2.func is called 15 | 16 | from dir_for_mod import mod2 17 | 18 | mod2.func() 19 | # -- dir_for_mod.mod2.func is called 20 | 21 | from dir_for_mod.mod2 import func 22 | 23 | func() 24 | # -- dir_for_mod.mod2.func is called 25 | -------------------------------------------------------------------------------- /notebook/urllib_request.py: -------------------------------------------------------------------------------- 1 | # http://docs.python.jp/3.6/library/urllib.request.html 2 | 3 | import urllib.request 4 | 5 | url = "https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png" 6 | path = "data/src/lena_square.png" 7 | 8 | result = urllib.request.urlretrieve(url, path) 9 | print(result) 10 | # ('data/src/lena_square.png', ) 11 | 12 | data = urllib.request.urlopen(url).read() 13 | with open(path, mode="wb") as f: 14 | f.write(data) 15 | -------------------------------------------------------------------------------- /notebook/sys_argv_test.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print('sys.argv : ', sys.argv) 4 | print('type(sys.argv) : ', type(sys.argv)) 5 | print('len(sys.argv) : ', len(sys.argv)) 6 | 7 | print() 8 | 9 | print('sys.argv[0] : ', sys.argv[0]) 10 | print('sys.argv[1] : ', sys.argv[1]) 11 | print('sys.argv[2] : ', sys.argv[2]) 12 | print('type(sys.argv[0]): ', type(sys.argv[0])) 13 | print('type(sys.argv[1]): ', type(sys.argv[1])) 14 | print('type(sys.argv[2]): ', type(sys.argv[2])) 15 | -------------------------------------------------------------------------------- /notebook/for_enumerate_zip.py: -------------------------------------------------------------------------------- 1 | names = ['Alice', 'Bob', 'Charlie'] 2 | ages = [24, 50, 18] 3 | 4 | for i, (name, age) in enumerate(zip(names, ages)): 5 | print(i, name, age) 6 | # 0 Alice 24 7 | # 1 Bob 50 8 | # 2 Charlie 18 9 | 10 | for i, t in enumerate(zip(names, ages)): 11 | print(i, t) 12 | # 0 ('Alice', 24) 13 | # 1 ('Bob', 50) 14 | # 2 ('Charlie', 18) 15 | 16 | for i, t in enumerate(zip(names, ages)): 17 | print(i, t[0], t[1]) 18 | # 0 Alice 24 19 | # 1 Bob 50 20 | # 2 Charlie 18 21 | -------------------------------------------------------------------------------- /notebook/import_example.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(type(math)) 4 | # 5 | 6 | print(math) 7 | # 8 | 9 | print(math.radians(180)) 10 | # 3.141592653589793 11 | 12 | print(type(math.radians)) 13 | # 14 | 15 | print(math.pi) 16 | # 3.141592653589793 17 | 18 | print(type(math.pi)) 19 | # 20 | -------------------------------------------------------------------------------- /notebook/numpy_lcm.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.array([0, 2, 3, 6]) 4 | b = np.array([3, 4, 5, 15]) 5 | 6 | print(np.lcm(a, b)) 7 | # [ 0 4 15 30] 8 | 9 | print(type(np.lcm(a, b))) 10 | # 11 | 12 | print(np.lcm(6, 15)) 13 | # 30 14 | 15 | a_2d = np.array([[0, 2, 3, 6], [0, 2, 3, 6]]) 16 | print(a_2d) 17 | # [[0 2 3 6] 18 | # [0 2 3 6]] 19 | 20 | print(np.lcm(a_2d, b)) 21 | # [[ 0 4 15 30] 22 | # [ 0 4 15 30]] 23 | 24 | print(np.lcm(a, 15)) 25 | # [ 0 30 15 30] 26 | -------------------------------------------------------------------------------- /notebook/pypdf_merge_dir.py: -------------------------------------------------------------------------------- 1 | import pypdf 2 | 3 | print(pypdf.__version__) 4 | # 5.5.0 5 | 6 | import glob 7 | import os 8 | 9 | def merge_pdf_in_dir(dir_path, dst_path): 10 | l = glob.glob(os.path.join(dir_path, '*.pdf')) 11 | l.sort() 12 | 13 | writer = pypdf.PdfWriter() 14 | for p in l: 15 | if not pypdf.PdfReader(p).is_encrypted: 16 | writer.append(p) 17 | 18 | writer.write(dst_path) 19 | 20 | merge_pdf_in_dir('data/src/pdf', 'data/temp/sample_dir.pdf') 21 | -------------------------------------------------------------------------------- /notebook/math_ceil.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.ceil(10.123)) 4 | # 11 5 | 6 | print(math.ceil(10.987)) 7 | # 11 8 | 9 | print(type(math.ceil(10.123))) 10 | # 11 | 12 | print(math.ceil(10)) 13 | # 10 14 | 15 | # print(math.ceil('10')) 16 | # TypeError: must be real number, not str 17 | 18 | print(hasattr(10, '__ceil__')) 19 | # True 20 | 21 | print(hasattr('10', '__ceil__')) 22 | # False 23 | 24 | print(math.ceil(-10.123)) 25 | # -10 26 | 27 | print(math.ceil(-10.987)) 28 | # -10 29 | -------------------------------------------------------------------------------- /notebook/my_package/import_example_inside_bash.sh: -------------------------------------------------------------------------------- 1 | pwd 2 | # /Users/mbp/Documents/my-project/python-snippets/notebook/my_package 3 | 4 | python3 main.py 5 | # Traceback (most recent call last): 6 | # File "main.py", line 1, in 7 | # from sub_package2 import sub_mod2 8 | # File "/Users/mbp/Documents/my-project/python-snippets/notebook/my_package/sub_package2/sub_mod2.py", line 1, in 9 | # from .. import mod1 10 | # ValueError: attempted relative import beyond top-level package 11 | -------------------------------------------------------------------------------- /notebook/numpy_method_chain.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | a = np.arange(12) 4 | a = a.reshape(3, 4) 5 | a = a.clip(2, 9) 6 | 7 | print(a) 8 | # [[2 2 2 3] 9 | # [4 5 6 7] 10 | # [8 9 9 9]] 11 | 12 | a_mc = np.arange(12).reshape(3, 4).clip(2, 9) 13 | 14 | print(a_mc) 15 | # [[2 2 2 3] 16 | # [4 5 6 7] 17 | # [8 9 9 9]] 18 | 19 | a_mc_parens = ( 20 | np.arange(12) 21 | .reshape(3, 4) 22 | .clip(2, 9) 23 | ) 24 | 25 | print(a_mc_parens) 26 | # [[2 2 2 3] 27 | # [4 5 6 7] 28 | # [8 9 9 9]] 29 | -------------------------------------------------------------------------------- /notebook/numpy_version.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.24.3 5 | 6 | print(np.version) 7 | # 8 | 9 | print(np.version.version) 10 | # 1.24.3 11 | 12 | print(np.version.short_version) 13 | # 1.24.3 14 | 15 | print(np.version.full_version) 16 | # 1.24.3 17 | 18 | print(np.version.git_revision) 19 | # 14bb214bca49b167abc375fa873466a811e62102 20 | 21 | print(np.version.release) 22 | # True 23 | -------------------------------------------------------------------------------- /notebook/shutil_rmtree.py: -------------------------------------------------------------------------------- 1 | import shutil 2 | import os 3 | 4 | os.makedirs('temp/dir/sub_dir/', exist_ok=True) 5 | 6 | with open('temp/dir/file.txt', 'w') as f: 7 | f.write('') 8 | 9 | print(os.listdir('temp/')) 10 | # ['dir'] 11 | 12 | print(os.listdir('temp/dir/')) 13 | # ['file.txt', 'sub_dir'] 14 | 15 | # shutil.rmtree('temp/dir/file.txt') 16 | # NotADirectoryError: [Errno 20] Not a directory: 'temp/dir/file.txt' 17 | 18 | shutil.rmtree('temp/dir/') 19 | 20 | print(os.listdir('temp/')) 21 | # [] 22 | -------------------------------------------------------------------------------- /notebook/str_partition_rpartition.py: -------------------------------------------------------------------------------- 1 | s = 'abc@xyz' 2 | print(s.partition('@')) 3 | # ('abc', '@', 'xyz') 4 | 5 | print(type(s.partition('@'))) 6 | # 7 | 8 | print(s.partition('123')) 9 | # ('abc@xyz', '', '') 10 | 11 | print(s.partition('abc')) 12 | # ('', 'abc', '@xyz') 13 | 14 | print(s.partition('xyz')) 15 | # ('abc@', 'xyz', '') 16 | 17 | s = 'abc@xyz@123' 18 | print(s.partition('@')) 19 | # ('abc', '@', 'xyz@123') 20 | 21 | print(s.rpartition('@')) 22 | # ('abc@xyz', '@', '123') 23 | -------------------------------------------------------------------------------- /notebook/atcoder-version-check.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import numpy 3 | import scipy 4 | 5 | print('Python: ', platform.python_version()) 6 | print('NumPy: ', numpy.__version__) 7 | print('SciPy: ', scipy.__version__) 8 | 9 | try: 10 | import sklearn 11 | import numba 12 | import networkx 13 | 14 | print('scikit-learn: ', sklearn.__version__) 15 | print('Numba: ', numba.__version__) 16 | print('NetworkX: ', networkx.__version__) 17 | except: 18 | pass 19 | -------------------------------------------------------------------------------- /notebook/math_fabs.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.fabs(-100)) 4 | # 100.0 5 | 6 | print(type(math.fabs(-100))) 7 | # 8 | 9 | print(math.fabs(-1.23)) 10 | # 1.23 11 | 12 | print(type(math.fabs(-1.23))) 13 | # 14 | 15 | # print(math.fabs(3 + 4j)) 16 | # TypeError: must be real number, not complex 17 | 18 | class MyClass: 19 | def __abs__(self): 20 | return 100 21 | 22 | mc = MyClass() 23 | 24 | # math.fabs(mc) 25 | # TypeError: must be real number, not MyClass 26 | -------------------------------------------------------------------------------- /notebook/import_example_package_collections.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | print(collections) 4 | # 5 | 6 | print(collections.Counter) 7 | # 8 | 9 | # import collections.Counter 10 | # ModuleNotFoundError: No module named 'collections.Counter' 11 | 12 | from collections import Counter 13 | 14 | print(Counter) 15 | # 16 | -------------------------------------------------------------------------------- /notebook/jupyter_youtube_vimeo.py: -------------------------------------------------------------------------------- 1 | import IPython.display 2 | 3 | IPython.display.YouTubeVideo('6XvmhE1J9PY') 4 | # 5 | 6 | IPython.display.YouTubeVideo('6XvmhE1J9PY', width=480, height=270) 7 | # 8 | 9 | IPython.display.YouTubeVideo('6XvmhE1J9PY', start=30) 10 | # 11 | 12 | IPython.display.VimeoVideo('289502328') 13 | # 14 | -------------------------------------------------------------------------------- /notebook/math_floor.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | print(math.floor(10.123)) 4 | # 10 5 | 6 | print(math.floor(10.987)) 7 | # 10 8 | 9 | print(type(math.floor(10.123))) 10 | # 11 | 12 | print(math.floor(10)) 13 | # 10 14 | 15 | # print(math.floor('10')) 16 | # TypeError: must be real number, not str 17 | 18 | print(hasattr(10, '__floor__')) 19 | # True 20 | 21 | print(hasattr('10', '__floor__')) 22 | # False 23 | 24 | print(math.floor(-10.123)) 25 | # -11 26 | 27 | print(math.floor(-10.987)) 28 | # -11 29 | -------------------------------------------------------------------------------- /notebook/round_towards_infinity.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def round_towards_infinity(x): 4 | return int(math.copysign(math.ceil(abs(x)), x)) 5 | 6 | print(round_towards_infinity(10.123)) 7 | # 11 8 | 9 | print(round_towards_infinity(-10.123)) 10 | # -11 11 | 12 | print(math.floor(10.123)) 13 | # 10 14 | 15 | print(math.floor(-10.123)) 16 | # -11 17 | 18 | print(math.ceil(10.123)) 19 | # 11 20 | 21 | print(math.ceil(-10.123)) 22 | # -10 23 | 24 | print(int(10.123)) 25 | # 10 26 | 27 | print(int(-10.123)) 28 | # -10 29 | -------------------------------------------------------------------------------- /notebook/list_str_re.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | l = ['oneXXXaaa', 'twoXXXbbb', 'three999aaa', '000111222'] 4 | 5 | l_re_match = [s for s in l if re.match('.*XXX.*', s)] 6 | print(l_re_match) 7 | # ['oneXXXaaa', 'twoXXXbbb'] 8 | 9 | l_re_sub_all = [re.sub('(.*)XXX(.*)', r'\2---\1', s) for s in l] 10 | print(l_re_sub_all) 11 | # ['aaa---one', 'bbb---two', 'three999aaa', '000111222'] 12 | 13 | l_re_sub = [re.sub('(.*)XXX(.*)', r'\2---\1', s) for s in l if re.match('.*XXX.*', s)] 14 | print(l_re_sub) 15 | # ['aaa---one', 'bbb---two'] 16 | -------------------------------------------------------------------------------- /notebook/pillow_invert.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageOps 2 | 3 | im = Image.open('data/src/lena.jpg') 4 | im_invert = ImageOps.invert(im) 5 | im_invert.save('data/dst/lena_invert.jpg', quality=95) 6 | 7 | # ![lena](data/src/lena.jpg) 8 | # ![lena_invert](data/dst/lena_invert.jpg) 9 | 10 | im = Image.open('data/src/horse.png').convert('RGB') 11 | im_invert = ImageOps.invert(im) 12 | im_invert.save('data/dst/horse_invert.png') 13 | 14 | # ![horse_invert](data/src/horse.png) 15 | # ![horse_invert](data/dst/horse_invert.png) 16 | -------------------------------------------------------------------------------- /notebook/pypdf_metadata_xmp.py: -------------------------------------------------------------------------------- 1 | import pypdf 2 | 3 | print(pypdf.__version__) 4 | # 5.5.0 5 | 6 | pdf = pypdf.PdfReader('data/temp/Simple PDF 2.0 file.pdf') 7 | print(pdf.metadata) 8 | # None 9 | 10 | print(type(pdf.xmp_metadata)) 11 | # 12 | 13 | print(pdf.xmp_metadata.dc_title) 14 | # {'x-default': 'A simple PDF 2.0 example file'} 15 | 16 | print(pdf.xmp_metadata.pdf_keywords) 17 | # PDF 2.0 sample example 18 | 19 | print(pdf.xmp_metadata.xmp_metadata_date) 20 | # 2017-07-11 07:55:11 21 | -------------------------------------------------------------------------------- /notebook/csv_numpy.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | with open('data/src/sample.csv') as f: 4 | print(f.read()) 5 | # 11,12,13,14 6 | # 21,22,23,24 7 | # 31,32,33,34 8 | 9 | a = np.loadtxt('data/src/sample.csv', delimiter=',') 10 | print(type(a)) 11 | # 12 | 13 | print(a) 14 | # [[11. 12. 13. 14.] 15 | # [21. 22. 23. 24.] 16 | # [31. 32. 33. 34.]] 17 | 18 | print(a[1:, :2]) 19 | # [[21. 22.] 20 | # [31. 32.]] 21 | 22 | print(a.mean()) 23 | # 22.5 24 | 25 | print(a.sum(axis=0)) 26 | # [63. 66. 69. 72.] 27 | -------------------------------------------------------------------------------- /notebook/opencv_flip.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | img = cv2.imread('data/src/lena.jpg') 4 | print(type(img)) 5 | # 6 | 7 | print(img.shape) 8 | # (225, 400, 3) 9 | 10 | img_flip_ud = cv2.flip(img, 0) 11 | cv2.imwrite('data/dst/lena_cv_flip_ud.jpg', img_flip_ud) 12 | # True 13 | 14 | img_flip_lr = cv2.flip(img, 1) 15 | cv2.imwrite('data/dst/lena_cv_flip_lr.jpg', img_flip_lr) 16 | # True 17 | 18 | img_flip_ud_lr = cv2.flip(img, -1) 19 | cv2.imwrite('data/dst/lena_cv_flip_ud_lr.jpg', img_flip_ud_lr) 20 | # True 21 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_read_camera.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | cap_cam = cv2.VideoCapture(0) 4 | print(type(cap_cam)) 5 | # 6 | 7 | print(cap_cam.isOpened()) 8 | # True 9 | 10 | print(cap_cam.get(cv2.CAP_PROP_POS_FRAMES)) 11 | # 0.0 12 | 13 | ret, frame = cap_cam.read() 14 | 15 | print(ret) 16 | # True 17 | 18 | print(type(frame)) 19 | # 20 | 21 | print(frame.shape) 22 | # (720, 1280, 3) 23 | 24 | print(cap_cam.get(cv2.CAP_PROP_POS_FRAMES)) 25 | # 0.0 26 | 27 | cap_cam.release() 28 | -------------------------------------------------------------------------------- /notebook/numpy_random_distributions.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.1 5 | 6 | rng = np.random.default_rng() 7 | 8 | print(rng.binomial(10, 0.5, (2, 3))) 9 | # [[3 7 5] 10 | # [4 3 5]] 11 | 12 | print(rng.beta(2, 2, (2, 3))) 13 | # [[0.84643935 0.50674151 0.30812967] 14 | # [0.52728096 0.76007311 0.26255972]] 15 | 16 | print(rng.gamma(5, 1, (2, 3))) 17 | # [[5.6484851 8.28210475 2.65957385] 18 | # [2.00776839 6.65851101 7.77808412]] 19 | 20 | print(rng.poisson(4, (2, 3))) 21 | # [[1 6 3] 22 | # [5 2 1]] 23 | -------------------------------------------------------------------------------- /notebook/numpy_image_split_color.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import numpy as np 3 | 4 | im = np.array(Image.open('data/src/lena_square.png')) 5 | 6 | im_R = im.copy() 7 | im_R[:, :, (1, 2)] = 0 8 | im_G = im.copy() 9 | im_G[:, :, (0, 2)] = 0 10 | im_B = im.copy() 11 | im_B[:, :, (0, 1)] = 0 12 | 13 | im_RGB = np.concatenate((im_R, im_G, im_B), axis=1) 14 | # im_RGB = np.hstack((im_R, im_G, im_B)) 15 | # im_RGB = np.c_['1', im_R, im_G, im_B] 16 | 17 | pil_img = Image.fromarray(im_RGB) 18 | pil_img.save('data/dst/lena_numpy_split_color.jpg') 19 | -------------------------------------------------------------------------------- /notebook/numpy_vsplit.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.1 5 | 6 | a = np.arange(16).reshape(4, 4) 7 | print(a) 8 | # [[ 0 1 2 3] 9 | # [ 4 5 6 7] 10 | # [ 8 9 10 11] 11 | # [12 13 14 15]] 12 | 13 | a0, a1 = np.vsplit(a, 2) 14 | 15 | print(a0) 16 | # [[0 1 2 3] 17 | # [4 5 6 7]] 18 | 19 | print(a1) 20 | # [[ 8 9 10 11] 21 | # [12 13 14 15]] 22 | 23 | a0, a1 = np.split(a, [1]) 24 | 25 | print(a0) 26 | # [[0 1 2 3]] 27 | 28 | print(a1) 29 | # [[ 4 5 6 7] 30 | # [ 8 9 10 11] 31 | # [12 13 14 15]] 32 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_play_file.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import sys 3 | 4 | file_path = 'data/temp/sample_video.mp4' 5 | delay = 1 6 | window_name = 'frame' 7 | 8 | cap = cv2.VideoCapture(file_path) 9 | 10 | if not cap.isOpened(): 11 | sys.exit() 12 | 13 | while True: 14 | ret, frame = cap.read() 15 | if ret: 16 | cv2.imshow(window_name, frame) 17 | if cv2.waitKey(delay) & 0xFF == ord('q'): 18 | break 19 | else: 20 | cap.set(cv2.CAP_PROP_POS_FRAMES, 0) 21 | 22 | cv2.destroyWindow(window_name) 23 | -------------------------------------------------------------------------------- /notebook/opencv_videocapture_realtime.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import sys 3 | 4 | camera_id = 0 5 | delay = 1 6 | window_name = 'frame' 7 | 8 | cap = cv2.VideoCapture(camera_id) 9 | 10 | if not cap.isOpened(): 11 | sys.exit() 12 | 13 | while True: 14 | ret, frame = cap.read() 15 | 16 | gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 17 | blur = cv2.GaussianBlur(gray, (0, 0), 5) 18 | 19 | cv2.imshow(window_name, blur) 20 | if cv2.waitKey(delay) & 0xFF == ord('q'): 21 | break 22 | 23 | cv2.destroyWindow(window_name) 24 | -------------------------------------------------------------------------------- /notebook/pass_exception.py: -------------------------------------------------------------------------------- 1 | def divide(a, b): 2 | print(a / b) 3 | 4 | # divide(1, 0) 5 | # ZeroDivisionError: division by zero 6 | 7 | def divide_exception(a, b): 8 | try: 9 | print(a / b) 10 | except ZeroDivisionError as e: 11 | print('ZeroDivisionError: ', e) 12 | 13 | divide_exception(1, 0) 14 | # ZeroDivisionError: division by zero 15 | 16 | def divide_exception_pass(a, b): 17 | try: 18 | print(a / b) 19 | except ZeroDivisionError as e: 20 | pass 21 | 22 | divide_exception_pass(1, 0) 23 | -------------------------------------------------------------------------------- /notebook/str_num_conversion_unicodedata.py: -------------------------------------------------------------------------------- 1 | import unicodedata 2 | 3 | print(unicodedata.numeric('五')) 4 | print(type(unicodedata.numeric('五'))) 5 | # 5.0 6 | # 7 | 8 | print(unicodedata.numeric('十')) 9 | # 10.0 10 | 11 | print(unicodedata.numeric('参')) 12 | # 3.0 13 | 14 | print(unicodedata.numeric('億')) 15 | # 100000000.0 16 | 17 | # print(unicodedata.numeric('五十')) 18 | # TypeError: numeric() argument 1 must be a unicode character, not str 19 | 20 | # print(unicodedata.numeric('漢')) 21 | # ValueError: not a numeric character 22 | -------------------------------------------------------------------------------- /notebook/for_range.py: -------------------------------------------------------------------------------- 1 | for i in range(3): 2 | print(i) 3 | # 0 4 | # 1 5 | # 2 6 | 7 | print(range(3)) 8 | print(type(range(3))) 9 | # range(0, 3) 10 | # 11 | 12 | print(list(range(3))) 13 | # [0, 1, 2] 14 | 15 | print(list(range(6))) 16 | # [0, 1, 2, 3, 4, 5] 17 | 18 | print(list(range(10, 13))) 19 | # [10, 11, 12] 20 | 21 | print(list(range(0, 10, 3))) 22 | # [0, 3, 6, 9] 23 | 24 | print(list(range(10, 0, -3))) 25 | # [10, 7, 4, 1] 26 | 27 | for i in range(10, 0, -3): 28 | print(i) 29 | # 10 30 | # 7 31 | # 4 32 | # 1 33 | -------------------------------------------------------------------------------- /notebook/str_remove_slice.py: -------------------------------------------------------------------------------- 1 | s = '0123456789' 2 | 3 | print(s[3:7]) 4 | # 3456 5 | 6 | print(s[3:-3]) 7 | # 3456 8 | 9 | print(s[:5]) 10 | # 01234 11 | 12 | print(s[5:]) 13 | # 56789 14 | 15 | print(s[:3] + s[6:]) 16 | # 0126789 17 | 18 | def remove_str_start_end(s, start, end): 19 | return s[:start] + s[end + 1:] 20 | 21 | print(remove_str_start_end(s, 3, 5)) 22 | # 0126789 23 | 24 | def remove_str_start_length(s, start, length): 25 | return s[:start] + s[start + length:] 26 | 27 | print(remove_str_start_length(s, 3, 5)) 28 | # 01289 29 | -------------------------------------------------------------------------------- /notebook/calendar_leap.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | print(calendar.isleap(2019)) 4 | # False 5 | 6 | print(calendar.isleap(2020)) 7 | # True 8 | 9 | print(calendar.isleap(1900)) 10 | # False 11 | 12 | print(calendar.isleap(2000)) 13 | # True 14 | 15 | print(calendar.leapdays(2019, 2030)) 16 | # 3 17 | 18 | print(calendar.leapdays(2019, 2020)) 19 | # 0 20 | 21 | print([y for y in range(2019, 2030) if calendar.isleap(y)]) 22 | # [2020, 2024, 2028] 23 | 24 | print([y for y in range(2000, 2020) if calendar.isleap(y)]) 25 | # [2000, 2004, 2008, 2012, 2016] 26 | -------------------------------------------------------------------------------- /notebook/pathlib_cwd.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | 3 | p = Path.cwd() 4 | print(p) 5 | # /Users/mbp/Documents/my-project/python-snippets/notebook 6 | 7 | print(type(p)) 8 | # 9 | 10 | print(p.cwd()) 11 | # /Users/mbp/Documents/my-project/python-snippets/notebook 12 | 13 | import os 14 | 15 | os.chdir(p.parent) 16 | 17 | print(Path.cwd()) 18 | # /Users/mbp/Documents/my-project/python-snippets 19 | 20 | os.chdir(p / 'data') 21 | 22 | print(Path.cwd()) 23 | # /Users/mbp/Documents/my-project/python-snippets/notebook/data 24 | -------------------------------------------------------------------------------- /notebook/dir_import_test/import_example_absolute_bash.sh: -------------------------------------------------------------------------------- 1 | pwd 2 | # /Users/mbp/Documents/my-project/python-snippets/notebook/dir_import_test 3 | 4 | python3 dir/main_absolute.py 5 | # -- mod1.func is called 6 | # -- dir_for_mod.mod2.func is called 7 | 8 | cd dir 9 | 10 | pwd 11 | # /Users/mbp/Documents/my-project/python-snippets/notebook/dir_import_test/dir 12 | 13 | python3 main_absolute.py 14 | # Traceback (most recent call last): 15 | # File "main_absolute.py", line 1, in 16 | # import mod1 17 | # ModuleNotFoundError: No module named 'mod1' 18 | -------------------------------------------------------------------------------- /notebook/opencv_add_weighted.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | 3 | src1 = cv2.imread('data/src/lena.jpg') 4 | src2 = cv2.imread('data/src/rocket.jpg') 5 | 6 | src2 = cv2.resize(src2, src1.shape[1::-1]) 7 | 8 | dst = cv2.addWeighted(src1, 0.5, src2, 0.5, 0) 9 | 10 | cv2.imwrite('data/dst/opencv_add_weighted.jpg', dst) 11 | # True 12 | 13 | # ![](data/dst/opencv_add_weighted.jpg) 14 | 15 | dst = cv2.addWeighted(src1, 0.5, src2, 0.2, 128) 16 | 17 | cv2.imwrite('data/dst/opencv_add_weighted_gamma.jpg', dst) 18 | # True 19 | 20 | # ![](data/dst/opencv_add_weighted_gamma.jpg) 21 | -------------------------------------------------------------------------------- /notebook/jupyter_precision_pandas.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | df = pd.DataFrame({'a': [0.123456789], 'b': [0.987654321]}) 4 | 5 | df 6 | # a b 7 | # 0 0.123457 0.987654 8 | 9 | print(pd.options.display.precision) 10 | # 6 11 | 12 | %precision 3 13 | # '%.3f' 14 | 15 | print(pd.options.display.precision) 16 | # 6 17 | 18 | df 19 | # a b 20 | # 0 0.123457 0.987654 21 | 22 | pd.options.display.precision = 3 23 | 24 | df 25 | # a b 26 | # 0 0.123 0.988 27 | 28 | print(df) 29 | # a b 30 | # 0 0.123 0.988 31 | -------------------------------------------------------------------------------- /notebook/matplotlib_seaborn.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import seaborn as sns 4 | 5 | sns.set() 6 | sns.set_style("whitegrid", {'grid.linestyle': '--'}) 7 | sns.set_context("paper", 1.5, {"lines.linewidth": 4}) 8 | sns.set_palette("winter_r", 8, 1) 9 | sns.set('talk', 'whitegrid', 'dark', font_scale=1.5, 10 | rc={"lines.linewidth": 2, 'grid.linestyle': '--'}) 11 | 12 | x = np.arange(0, 2.1, 0.1) 13 | 14 | plt.plot(x, x) 15 | plt.plot(x, x**1.5) 16 | plt.plot(x, x**2) 17 | 18 | plt.savefig('data/dst/matplotlib_seaborn_set_all.png') 19 | -------------------------------------------------------------------------------- /notebook/platform_usage_win.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import os 3 | import sys 4 | 5 | print(platform.system()) 6 | # Windows 7 | 8 | print(os.name) 9 | # nt 10 | 11 | print(sys.platform) 12 | # win32 13 | 14 | print(platform.release()) 15 | # 10 16 | 17 | print(platform.version()) 18 | # 10.0.22621 19 | 20 | print(platform.platform()) 21 | # Windows-10-10.0.22621-SP0 22 | 23 | print(platform.win32_ver()) 24 | # ('10', '10.0.22621', 'SP0', 'Multiprocessor Free') 25 | 26 | print(platform.win32_edition()) 27 | # Core 28 | 29 | print(platform.win32_is_iot()) 30 | # False 31 | -------------------------------------------------------------------------------- /notebook/sklearn_confusion_matrix_heatmap.py: -------------------------------------------------------------------------------- 1 | from sklearn.metrics import confusion_matrix 2 | import seaborn as sns 3 | import matplotlib.pyplot as plt 4 | 5 | y_true = [0, 0, 0, 0, 0, 1, 1, 1, 1, 1] 6 | y_pred = [0, 1, 1, 1, 1, 0, 0, 0, 1, 1] 7 | 8 | cm = confusion_matrix(y_true, y_pred) 9 | 10 | print(cm) 11 | # [[1 4] 12 | # [3 2]] 13 | 14 | sns.heatmap(cm) 15 | plt.savefig('data/dst/sklearn_confusion_matrix.png') 16 | plt.close() 17 | 18 | sns.heatmap(cm, annot=True, cmap='Blues') 19 | plt.savefig('data/dst/sklearn_confusion_matrix_annot_blues.png') 20 | plt.close() 21 | -------------------------------------------------------------------------------- /notebook/dict_swap_key_value.py: -------------------------------------------------------------------------------- 1 | d = {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'} 2 | 3 | d_swap = {v: k for k, v in d.items()} 4 | print(d_swap) 5 | # {'val1': 'key1', 'val2': 'key2', 'val3': 'key3'} 6 | 7 | def get_swap_dict(d): 8 | return {v: k for k, v in d.items()} 9 | 10 | d_swap = get_swap_dict(d) 11 | print(d_swap) 12 | # {'val1': 'key1', 'val2': 'key2', 'val3': 'key3'} 13 | 14 | d_duplicate = {'key1': 'val1', 'key2': 'val1', 'key3': 'val3'} 15 | 16 | d_duplicate_swap = get_swap_dict(d_duplicate) 17 | print(d_duplicate_swap) 18 | # {'val1': 'key2', 'val3': 'key3'} 19 | -------------------------------------------------------------------------------- /notebook/dir_import_test/import_example_relative_bash.sh: -------------------------------------------------------------------------------- 1 | pwd 2 | # /Users/mbp/Documents/my-project/python-snippets/notebook/dir_import_test 3 | 4 | python3 dir/main_relative.py 5 | # Traceback (most recent call last): 6 | # File "dir/main_relative.py", line 1, in 7 | # from .. import mod1 8 | # ValueError: attempted relative import beyond top-level package 9 | 10 | cd .. 11 | 12 | pwd 13 | # /Users/mbp/Documents/my-project/python-snippets/notebook 14 | 15 | python3 -m dir_import_test.dir.main_relative 16 | # -- mod1.func is called 17 | # -- dir_for_mod.mod2.func is called 18 | -------------------------------------------------------------------------------- /notebook/any_example.py: -------------------------------------------------------------------------------- 1 | print(any([True, False, False])) 2 | # True 3 | 4 | print(any([False, False, False])) 5 | # False 6 | 7 | print(any((True, False, False))) 8 | # True 9 | 10 | print(any({True, False, False})) 11 | # True 12 | 13 | print(any(['aaa', 'bbb', 'ccc', ''])) 14 | # True 15 | 16 | print(any(['', '', '', ''])) 17 | # False 18 | 19 | print(any([0, 1, 2, 3])) 20 | # True 21 | 22 | print(any([0, 0, 0, 0])) 23 | # False 24 | 25 | print(any([])) 26 | # False 27 | 28 | print(not any([False, False, False])) 29 | # True 30 | 31 | print(not any([True, False, False])) 32 | # False 33 | -------------------------------------------------------------------------------- /notebook/matplotlib_patches.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import matplotlib.patches as patches 3 | 4 | fig = plt.figure() 5 | ax = plt.axes() 6 | 7 | # fc = face color, ec = edge color 8 | c = patches.Circle(xy=(0, 0), radius=0.5, fc='g', ec='r') 9 | e = patches.Ellipse(xy=(-0.25, 0), width=0.5, height=0.25, fc='b', ec='y') 10 | r = patches.Rectangle(xy=(0, 0), width=0.25, height=0.5, ec='#000000', fill=False) 11 | ax.add_patch(c) 12 | ax.add_patch(e) 13 | ax.add_patch(r) 14 | 15 | plt.axis('scaled') 16 | ax.set_aspect('equal') 17 | 18 | plt.savefig('data/dst/matplotlib_patches.png') 19 | -------------------------------------------------------------------------------- /notebook/sys_version.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print(sys.version) 4 | # 3.11.3 (main, Apr 7 2023, 20:13:31) [Clang 14.0.0 (clang-1400.0.29.202)] 5 | 6 | print(type(sys.version)) 7 | # 8 | 9 | print(sys.version_info) 10 | # sys.version_info(major=3, minor=11, micro=3, releaselevel='final', serial=0) 11 | 12 | print(type(sys.version_info)) 13 | # 14 | 15 | print(sys.version_info[0]) 16 | # 3 17 | 18 | print(sys.version_info.major) 19 | # 3 20 | 21 | if sys.version_info[0] == 3: 22 | print('Python3') 23 | else: 24 | print('Python2') 25 | # Python3 26 | -------------------------------------------------------------------------------- /notebook/dict_comprehension.py: -------------------------------------------------------------------------------- 1 | d = {'apple': 1, 'banana': 10, 'orange': 100} 2 | 3 | dc = {k: v for k, v in d.items() if v % 2 == 0} 4 | print(dc) 5 | # {'banana': 10, 'orange': 100} 6 | 7 | dc = {k: v for k, v in d.items() if v % 2 == 1} 8 | print(dc) 9 | # {'apple': 1} 10 | 11 | dc = {k: v for k, v in d.items() if k.endswith('e')} 12 | print(dc) 13 | # {'apple': 1, 'orange': 100} 14 | 15 | dc = {k: v for k, v in d.items() if not k.endswith('e')} 16 | print(dc) 17 | # {'banana': 10} 18 | 19 | dc = {k: v for k, v in d.items() if v % 2 == 0 and k.endswith('e')} 20 | print(dc) 21 | # {'orange': 100} 22 | -------------------------------------------------------------------------------- /notebook/dict_get.py: -------------------------------------------------------------------------------- 1 | d = {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'} 2 | 3 | print(d['key1']) 4 | # val1 5 | 6 | # print(d['key4']) 7 | # KeyError: 'key4' 8 | 9 | d['key4'] = 'val4' 10 | print(d) 11 | # {'key1': 'val1', 'key2': 'val2', 'key3': 'val3', 'key4': 'val4'} 12 | 13 | d = {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'} 14 | 15 | print(d.get('key1')) 16 | # val1 17 | 18 | print(d.get('key4')) 19 | # None 20 | 21 | print(d.get('key4', 'NO KEY')) 22 | # NO KEY 23 | 24 | print(d.get('key4', 100)) 25 | # 100 26 | 27 | print(d) 28 | # {'key1': 'val1', 'key2': 'val2', 'key3': 'val3'} 29 | -------------------------------------------------------------------------------- /notebook/platform_usage_ubuntu.py: -------------------------------------------------------------------------------- 1 | import platform 2 | import os 3 | import sys 4 | 5 | print(platform.system()) 6 | # Linux 7 | 8 | print(os.name) 9 | # posix 10 | 11 | print(sys.platform) 12 | # linux 13 | 14 | print(platform.release()) 15 | # 5.15.0-86-generic 16 | 17 | print(platform.version()) 18 | # #96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023 19 | 20 | print(platform.platform()) 21 | # Linux-5.15.0-86-generic-x86_64-with-glibc2.35 22 | 23 | import distro 24 | 25 | print(distro.name()) 26 | # Ubuntu 27 | 28 | print(distro.id()) 29 | # ubuntu 30 | 31 | print(distro.version()) 32 | # 22.04 33 | -------------------------------------------------------------------------------- /notebook/collections_counter_timeit.py: -------------------------------------------------------------------------------- 1 | import collections 2 | 3 | l_100 = list(range(100)) 4 | 5 | %%timeit 6 | collections.Counter(l_100) 7 | # 7.36 µs ± 205 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each) 8 | 9 | l_10000 = list(range(10000)) 10 | 11 | %%timeit 12 | collections.Counter(l_10000) 13 | # 435 µs ± 22.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) 14 | 15 | l_10000_2 = list(range(100)) * 100 16 | print(len(l_10000_2)) 17 | # 10000 18 | 19 | %%timeit 20 | collections.Counter(l_10000_2) 21 | # 366 µs ± 3.86 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) 22 | -------------------------------------------------------------------------------- /notebook/os_removedirs.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pathlib import Path 3 | 4 | os.chdir('data/temp') 5 | 6 | p = Path('temp') 7 | p.joinpath('dir1/dir2/dir3').mkdir(parents=True, exist_ok=True) 8 | p.joinpath('dir1/file.txt').touch() 9 | 10 | !tree temp -nF 11 | # temp/ 12 | # └── dir1/ 13 | # ├── dir2/ 14 | # │   └── dir3/ 15 | # └── file.txt 16 | # 17 | # 4 directories, 1 file 18 | 19 | os.removedirs('temp/dir1/dir2/dir3') 20 | 21 | !tree temp -nF 22 | # temp/ 23 | # └── dir1/ 24 | # └── file.txt 25 | # 26 | # 2 directories, 1 file 27 | 28 | import shutil 29 | 30 | shutil.rmtree('temp') 31 | -------------------------------------------------------------------------------- /notebook/pillow_image.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageFilter 2 | 3 | im = Image.open('data/src/lena_square.png') 4 | 5 | # ![lena_square](data/src/lena_square.png) 6 | 7 | print(im.format, im.size, im.mode) 8 | # PNG (512, 512) RGB 9 | 10 | print(im.getextrema()) 11 | # ((54, 255), (3, 248), (8, 225)) 12 | 13 | print(im.getpixel((256, 256))) 14 | # (180, 65, 72) 15 | 16 | new_im = im.convert('L').rotate(90).filter(ImageFilter.GaussianBlur()) 17 | 18 | new_im.show() 19 | 20 | new_im.save('data/dst/lena_square_pillow.jpg', quality=95) 21 | 22 | # ![lena_square_pillow](data/dst/lena_square_pillow.jpg) 23 | -------------------------------------------------------------------------------- /notebook/pillow_size.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | 3 | im = Image.open('data/src/lena.jpg') 4 | 5 | print(im.size) 6 | print(type(im.size)) 7 | # (400, 225) 8 | # 9 | 10 | w, h = im.size 11 | print('width: ', w) 12 | print('height:', h) 13 | # width: 400 14 | # height: 225 15 | 16 | print('width: ', im.width) 17 | print('height:', im.height) 18 | # width: 400 19 | # height: 225 20 | 21 | im_gray = Image.open('data/src/lena.jpg').convert('L') 22 | 23 | print(im.size) 24 | print('width: ', im.width) 25 | print('height:', im.height) 26 | # (400, 225) 27 | # width: 400 28 | # height: 225 29 | -------------------------------------------------------------------------------- /notebook/import_example_from.py: -------------------------------------------------------------------------------- 1 | from math import pi 2 | 3 | print(pi) 4 | # 3.141592653589793 5 | 6 | # print(math.radians(180)) 7 | # NameError: name 'math' is not defined 8 | 9 | from math import pi, radians 10 | 11 | print(pi) 12 | # 3.141592653589793 13 | 14 | print(radians(180)) 15 | # 3.141592653589793 16 | 17 | from math import ( 18 | e, 19 | exp 20 | ) 21 | 22 | print(e) 23 | # 2.718281828459045 24 | 25 | print(exp(1)) 26 | # 2.718281828459045 27 | 28 | from math import * 29 | 30 | print(pi) 31 | # 3.141592653589793 32 | 33 | print(cos(0)) 34 | # 1.0 35 | 36 | print(sin(0)) 37 | # 0.0 38 | -------------------------------------------------------------------------------- /notebook/pandas_str_num_conversion_separator.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | 3 | s_sep = pd.Series(['1,000,000', '1,000', '1']) 4 | print(s_sep) 5 | # 0 1,000,000 6 | # 1 1,000 7 | # 2 1 8 | # dtype: object 9 | 10 | # print(s_sep.astype(int)) 11 | # ValueError: invalid literal for int() with base 10: '1,000,000' 12 | 13 | print(s_sep.str.replace(',', '').astype(int)) 14 | # 0 1000000 15 | # 1 1000 16 | # 2 1 17 | # dtype: int64 18 | 19 | print(s_sep.str.replace(',', '').astype(float)) 20 | # 0 1000000.0 21 | # 1 1000.0 22 | # 2 1.0 23 | # dtype: float64 24 | -------------------------------------------------------------------------------- /notebook/tensorflow_variable.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | 3 | var = tf.Variable(10) 4 | const = tf.constant(5) 5 | calc_op = var * const 6 | assign_op = tf.assign(var, calc_op) 7 | 8 | with tf.Session() as sess: 9 | sess.run(tf.global_variables_initializer()) 10 | 11 | print(sess.run(var)) 12 | 13 | sess.run(assign_op) 14 | print(sess.run(var)) 15 | 16 | sess.run(assign_op) 17 | print(sess.run(var)) 18 | # 10 19 | # 50 20 | # 250 21 | 22 | with tf.Session() as sess: 23 | sess.run(tf.global_variables_initializer()) 24 | 25 | print(sess.run(var)) 26 | # 10 27 | -------------------------------------------------------------------------------- /notebook/mojimoji_usage.py: -------------------------------------------------------------------------------- 1 | import mojimoji 2 | 3 | s = '123abc!?アイウエオ123abc!?アイウエオ' 4 | print(mojimoji.zen_to_han(s)) 5 | # 123abc!?アイウエオ123abc!?アイウエオ 6 | 7 | s = '123abc!?アイウエオ123abc!?アイウエオ' 8 | print(mojimoji.han_to_zen(s)) 9 | # 123abc!?アイウエオ123abc!?アイウエオ 10 | 11 | s = '123abc!?アイウエオ123abc!?アイウエオ' 12 | print(mojimoji.zen_to_han(s, kana=False)) 13 | # 123abc!?アイウエオ123abc!?アイウエオ 14 | 15 | print(mojimoji.han_to_zen(s, digit=False, ascii=False)) 16 | # 123abc!?アイウエオ123abc!?アイウエオ 17 | 18 | print(mojimoji.han_to_zen(mojimoji.zen_to_han(s, kana=False), digit=False, ascii=False)) 19 | # 123abc!?アイウエオ123abc!?アイウエオ 20 | -------------------------------------------------------------------------------- /notebook/numpy_ndarray_example.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | arr = np.array([0, 1, 2]) 4 | print(arr) 5 | # [0 1 2] 6 | 7 | arr_2d = np.array([[0, 1, 2], [3, 4, 5]]) 8 | print(arr_2d) 9 | # [[0 1 2] 10 | # [3 4 5]] 11 | 12 | print(arr[1]) 13 | # 1 14 | 15 | print(arr_2d[1, 1]) 16 | # 4 17 | 18 | print(arr_2d[0, 1:]) 19 | # [1 2] 20 | 21 | print(np.sqrt(arr_2d)) 22 | # [[0. 1. 1.41421356] 23 | # [1.73205081 2. 2.23606798]] 24 | 25 | arr_1 = np.array([[1, 2], [3, 4]]) 26 | arr_2 = np.array([[1, 2, 3], [4, 5, 6]]) 27 | 28 | print(np.dot(arr_1, arr_2)) 29 | # [[ 9 12 15] 30 | # [19 26 33]] 31 | -------------------------------------------------------------------------------- /notebook/int_bit_count.py: -------------------------------------------------------------------------------- 1 | i = 100 2 | print(bin(i)) 3 | # 0b1100100 4 | 5 | print(i.bit_count()) 6 | # 3 7 | 8 | i = 255 9 | print(bin(i)) 10 | # 0b11111111 11 | 12 | print(i.bit_count()) 13 | # 8 14 | 15 | i = -100 16 | print(bin(i)) 17 | # -0b1100100 18 | 19 | print(i.bit_count()) 20 | # 3 21 | 22 | i = -255 23 | print(bin(i)) 24 | # -0b11111111 25 | 26 | print(i.bit_count()) 27 | # 8 28 | 29 | def bit_count(self): 30 | return bin(self).count("1") 31 | 32 | print(bit_count(100)) 33 | # 3 34 | 35 | print(bit_count(255)) 36 | # 8 37 | 38 | print(bit_count(-100)) 39 | # 3 40 | 41 | print(bit_count(-255)) 42 | # 8 43 | -------------------------------------------------------------------------------- /notebook/matplotlib_example_multi.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | 4 | fig, ((ax00, ax01, ax02), (ax10, ax11, ax12)) = plt.subplots(nrows=2, ncols=3, sharey=True) 5 | 6 | x = np.arange(4) 7 | 8 | ax00.plot(x, x, 'ro--') 9 | ax01.plot(x, x**1.5, 'g^-.') 10 | ax02.plot(x, x**2, 'bs:') 11 | ax10.bar(x, x + 1, width=0.5, align='center', color='r') 12 | ax11.bar(x, x**1.5 + 1, width=0.5, align='center', color='g') 13 | ax12.bar(x, x**2 + 1, width=0.5, align='center', color='b') 14 | 15 | plt.rcParams['font.size'] = 10 16 | plt.tight_layout() 17 | 18 | plt.savefig("data/dst/matplotlib_example_multi.png") 19 | -------------------------------------------------------------------------------- /notebook/all_any_comprehension.py: -------------------------------------------------------------------------------- 1 | l = [0, 1, 2, 3, 4] 2 | 3 | print([i > 2 for i in l]) 4 | # [False, False, False, True, True] 5 | 6 | print(all([i > 2 for i in l])) 7 | # False 8 | 9 | print(any([i > 2 for i in l])) 10 | # True 11 | 12 | print(type([i > 2 for i in l])) 13 | # 14 | 15 | print(type((i > 2 for i in l))) 16 | # 17 | 18 | print(type(i > 2 for i in l)) 19 | # 20 | 21 | print(all(i > 2 for i in l)) 22 | # False 23 | 24 | print(any(i > 2 for i in l)) 25 | # True 26 | 27 | print(sum(i > 2 for i in l)) 28 | # 2 29 | 30 | print(sum(not (i > 2) for i in l)) 31 | # 3 32 | -------------------------------------------------------------------------------- /notebook/numpy_image_paste.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | src = np.array(Image.open('data/src/lena_square.png').resize((128, 128))) 5 | dst = np.array(Image.open('data/src/lena_square.png').resize((256, 256))) // 4 6 | 7 | dst_copy = dst.copy() 8 | dst_copy[64:128, 128:192] = src[32:96, 32:96] 9 | 10 | Image.fromarray(dst_copy).save('data/dst/lena_numpy_paste.jpg') 11 | 12 | # ![](data/dst/lena_numpy_paste.jpg) 13 | 14 | dst_copy = dst.copy() 15 | dst_copy[64:192, 64:192] = src 16 | 17 | Image.fromarray(dst_copy).save('data/dst/lena_numpy_paste_all.jpg') 18 | 19 | # ![](data/dst/lena_numpy_paste_all.jpg) 20 | -------------------------------------------------------------------------------- /notebook/numpy_select_basic.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.1 5 | 6 | a_2d = np.arange(12).reshape(3, 4) 7 | print(a_2d) 8 | # [[ 0 1 2 3] 9 | # [ 4 5 6 7] 10 | # [ 8 9 10 11]] 11 | 12 | print(a_2d[1, 2]) 13 | # 6 14 | 15 | print(a_2d[1]) 16 | # [4 5 6 7] 17 | 18 | print(a_2d[:, 1]) 19 | # [1 5 9] 20 | 21 | a_3d = np.arange(24).reshape(2, 3, 4) 22 | print(a_3d) 23 | # [[[ 0 1 2 3] 24 | # [ 4 5 6 7] 25 | # [ 8 9 10 11]] 26 | # 27 | # [[12 13 14 15] 28 | # [16 17 18 19] 29 | # [20 21 22 23]]] 30 | 31 | print(a_3d[1, [True, False, True], ::2]) 32 | # [[12 14] 33 | # [20 22]] 34 | -------------------------------------------------------------------------------- /notebook/opencv_mosaic_gif.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | from PIL import Image 3 | 4 | def mosaic(src, ratio=0.1): 5 | small = cv2.resize(src, None, fx=ratio, fy=ratio, interpolation=cv2.INTER_NEAREST) 6 | return cv2.resize(small, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST) 7 | 8 | src = cv2.cvtColor(cv2.imread('data/src/lena.jpg'), cv2.COLOR_BGR2RGB) 9 | 10 | imgs = [Image.fromarray(mosaic(src, 1 / i)) for i in range(1, 25)] 11 | imgs += imgs[-2::-1] + [Image.fromarray(src)] * 5 12 | 13 | imgs[0].save('data/temp/opencv_mosaic.gif', 14 | save_all=True, append_images=imgs[1:], optimize=False, duration=50, loop=0) 15 | -------------------------------------------------------------------------------- /notebook/pillow_image_draw.py: -------------------------------------------------------------------------------- 1 | from PIL import Image, ImageDraw, ImageFont 2 | 3 | im = Image.new("RGB", (512, 512), (128, 128, 128)) 4 | 5 | draw = ImageDraw.Draw(im) 6 | 7 | draw.line((0, im.height, im.width, 0), fill=(255, 0, 0), width=8) 8 | draw.rectangle((100, 100, 200, 200), fill=(0, 255, 0)) 9 | draw.ellipse((250, 300, 450, 400), fill=(0, 0, 255)) 10 | 11 | font = ImageFont.truetype('/Library/Fonts/Arial Bold.ttf', 48) 12 | draw.multiline_text((0, 0), 'Pillow sample', fill=(0, 0, 0), font=font) 13 | 14 | im.save('data/dst/pillow_iamge_draw.jpg', quality=95) 15 | 16 | # ![pillow_image_draw](data/dst/pillow_iamge_draw.jpg) 17 | -------------------------------------------------------------------------------- /notebook/numpy_pil_conversion.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PIL import Image 3 | 4 | src_path = "data/src/lena.jpg" 5 | img = Image.open(src_path).convert('RGB') 6 | 7 | # ![lena](data/src/lena.jpg) 8 | 9 | print(type(img)) 10 | # 11 | 12 | print(img.size) # (width, height) 13 | # (400, 225) 14 | 15 | # PIL Image to ndarray 16 | arr = np.array(img) 17 | print(type(arr)) 18 | # 19 | 20 | print(arr.shape) # (height, width, channel) 21 | # (225, 400, 3) 22 | 23 | # ndarray to PIL Image 24 | img2 = Image.fromarray(np.uint8(arr)) 25 | print(type(img2)) 26 | # 27 | -------------------------------------------------------------------------------- /notebook/re_compile.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | s = 'aaa@xxx.com bbb@yyy.net ccc@zzz.org' 4 | 5 | print(re.match(r'([a-z]+)@([a-z]+)\.com', s)) 6 | # 7 | 8 | print(re.sub(r'([a-z]+)@([a-z]+)\.com', 'NEW_ADDRESS', s)) 9 | # NEW_ADDRESS bbb@yyy.net ccc@zzz.org 10 | 11 | p = re.compile(r'([a-z]+)@([a-z]+)\.com') 12 | 13 | print(p) 14 | # re.compile('([a-z]+)@([a-z]+)\\.com') 15 | 16 | print(type(p)) 17 | # 18 | 19 | print(p.match(s)) 20 | # 21 | 22 | print(p.sub('NEW_ADDRESS', s)) 23 | # NEW_ADDRESS bbb@yyy.net ccc@zzz.org 24 | -------------------------------------------------------------------------------- /notebook/numpy_allclose.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.__version__) 4 | # 1.26.1 5 | 6 | a = np.array([0.3, 0.1 + 0.1 + 0.1]) 7 | b = np.array([0.3, 0.3]) 8 | c = np.array([0.1, 0.3]) 9 | 10 | print(np.allclose(a, b)) 11 | # True 12 | 13 | print(np.allclose(a, c)) 14 | # False 15 | 16 | a = np.array([99, 100, 101]) 17 | 18 | print(np.allclose(a, 100)) 19 | # False 20 | 21 | print(np.allclose(a, 100, rtol=0, atol=1)) 22 | # True 23 | 24 | a_nan = np.array([np.nan, 1, 2]) 25 | b_nan = np.array([np.nan, 1, 2]) 26 | 27 | print(np.allclose(a_nan, b_nan)) 28 | # False 29 | 30 | print(np.allclose(a_nan, b_nan, equal_nan=True)) 31 | # True 32 | --------------------------------------------------------------------------------