These articles cover a diverse range of topics including Saudi Arabia’s Vision 2030 and its impact on healthcare and economic diversification, developments in the Saudi stock market and concerns over US tariffs, and regional news such as the humanitarian crisis in Gaza and diplomatic discussions. Several pieces highlight Saudi Arabia’s cultural initiatives like mosque restoration and arts festivals, alongside social issues like land ownership for youth and traffic safety. Furthermore, the sources examine sports news, particularly football leagues, and international relations, focusing on trade tensions with Taiwan and Iraq’s internal dynamics concerning armed groups.
وزير الدفاع يبحث مع نظيره الأميركي تطورات الأوضاع الإقليمية
Source Material Study Guide
Quiz
According to the article, what is the significance of World Health Day, and when is it observed annually?
What are the primary goals of Saudi Arabia’s Health Sector Transformation Program, as outlined in the text?
What was the general trend of the “TASI” stock market index on Monday, April 7, 2025, and what factor was suggested to be influencing it?
Describe the initiative between the GCC countries and the European Union mentioned in the article. What is its aim?
How many journalists were reported to have been killed in Gaza since the beginning of the “genocidal war,” according to the information provided?
What was the main topic of discussion between the Saudi Minister of Defense and the US Secretary of Defense during their phone call?
What are some of the potential economic downsides for the United States if Taiwan were to fully restrict its market access, as discussed in the analysis piece?
What was the purpose of the campaign launched by the Emir of Jazan related to Prince Sultan bin Abdulaziz?
Briefly describe the second phase of the historical mosques restoration project mentioned in the article, including its objectives.
What was the main focus of the “Absher with Eid” initiative mentioned in the local news?
اقتصادي يحذر من استغلال الملاك لرفع الإيجارات خلال مدة الـ90 يوماً
Quiz Answer Key
World Health Day, observed annually on April 7th, serves as a global event to raise awareness about specific health topics of concern to the World Health Organization. It commemorates the founding of the WHO in 1948, and a theme is chosen each year to focus on a particular area of public health priority.
The primary goals of Saudi Arabia’s Health Sector Transformation Program are to develop a comprehensive, effective, and sustainable healthcare system. This includes focusing on preventative care, improving the quality and efficiency of healthcare services, ensuring fair and easy access for all citizens, promoting health awareness, and enhancing financial resource management in the health sector.
The “TASI” stock market index experienced a rebound during the mid-session trading on Monday, April 7, 2025, recovering some of its earlier losses. Analysts suggested that this recovery indicated the market was beginning to absorb the impact of the US tariff hike shock.
The initiative between the GCC countries and the European Union is a project to exchange radiological data between the GCC’s Center for Radiological Data Exchange and Emergency Management (GCC-RDEP) and the European Union. Its aim is to help limit the effects of radiological and nuclear disasters through early detection, analysis using advanced simulation systems, and providing technical recommendations for decision-makers in GCC countries.
According to the article, the number of journalists killed in Gaza since the beginning of the “genocidal war” had risen to 210 with the death of journalist Hifni al-Faq’awi.
The main topic of discussion between the Saudi Minister of Defense and the US Secretary of Defense during their phone call was the review of the Saudi-US defense relations, cooperation prospects, and the discussion of regional developments and mutual efforts to support the security and stability of both countries, the region, and the world, in addition to topics of common interest.
If Taiwan were to fully restrict its market access, the United States could potentially lose its current access to the Taiwanese market, which has become increasingly important due to concerns about a potential Chinese invasion of the island. Taiwan is a significant partner in the supply of vital components like semiconductors.
The purpose of the campaign launched by the Emir of Jazan related to Prince Sultan bin Abdulaziz for Autism was to raise awareness about autism spectrum disorder, enhance services provided to those affected and their families, and support training, social inclusion, awareness, and rehabilitation programs.
The second phase of the historical mosques restoration project aims to rehabilitate historical mosques for worship while preserving their authenticity and architectural heritage, highlighting their historical, cultural, and religious significance for the Kingdom, and contributing to the cultural dimension of Vision 2030. This phase follows the restoration of 30 historical mosques in 10 regions during the first phase.
The main focus of the “Absher with Eid” initiative was to bring joy and celebration to various segments of society during the Eid al-Fitr holiday. It involved activities in different cities and targeted various government sectors and community groups.
Essay Format Questions
Analyze the interconnectedness of the events reported in the provided source material, identifying potential underlying themes or relationships between seemingly disparate news items.
Discuss the potential implications of the US tariff policies, as described in the article, on both the Saudi Arabian economy and the broader global economic landscape.
Evaluate the significance of Saudi Arabia’s focus on health sector transformation and public health initiatives, as highlighted in the context of World Health Day and Vision 2030.
Critically examine the role of international cooperation, as exemplified by the GCC-EU radiological data exchange and the Saudi-US defense discussions, in addressing regional and global challenges.
Considering the various local and international news items presented, discuss the overall image of Saudi Arabia that emerges from this collection of excerpts.
Glossary of Key Terms
TASI (تاسي): An acronym for the Tadawul All Share Index, which is the main stock market index that tracks the performance of all listed companies on the Saudi Stock Exchange (Tadawul).
GCC (مجلس التعاون لدول الخليج العربية): The Gulf Cooperation Council, a regional intergovernmental political and economic union consisting of all Arab states of the Persian Gulf except for Iraq.
Vision 2030 (رؤية 2030): A strategic framework launched by Saudi Arabia to reduce its dependence on oil, diversify its economy, and develop public service sectors such as health, education, infrastructure, recreation, and tourism.
Tariffs (رسوم جمركية): Taxes imposed by a government on goods and services imported from other countries, often used to protect domestic industries or as a tool in international trade relations.
Radiological Data (بيانات إشعاعية): Information related to radioactivity and radioactive materials, often collected for monitoring environmental safety and managing potential nuclear or radiological incidents.
Health Sector Transformation Program (برنامج التحول الصحي): A key initiative under Saudi Arabia’s Vision 2030 aimed at overhauling and improving the national healthcare system.
Digital Transformation (تحول رقمي): The use of digital technologies to fundamentally change how a business or organization operates and delivers value. In the context of healthcare, this includes electronic health records, telemedicine, and other technology-driven solutions.
Privatization (الخصخصة): The transfer of ownership of a business, enterprise, agency, public service, or public property from the public sector (government) to the private sector.
“Wasfati” (وصفتي): An electronic prescription service launched by the Saudi Ministry of Health to streamline the process of obtaining medications for patients, reducing reliance on paper prescriptions.
Counter-Irjaf (مكافحة الإرجاف): Efforts to combat “Irjaf,” which refers to the spread of false news, rumors, and misinformation intended to cause public disorder and undermine security and stability.
Saudi Arabia: Developments and Global Engagement, April 2025
Here is a detailed briefing document summarizing the main themes and important ideas from the provided sources:
Briefing Document: Key Themes and Ideas from Recent Al-Riyadh Articles (April 8, 2025)
Source: Excerpts from Al-Riyadh Newspaper, Issue #20735, dated Tuesday, April 8, 2025 (10 Shawwal 1446 AH)
Main Themes:
Saudi Arabia’s Focus on Healthcare Advancement: The Kingdom is actively promoting health awareness and developing a comprehensive, efficient, and sustainable healthcare system in line with Vision 2030.
Economic Developments and Market Reactions: The Saudi stock market (“TASI”) is showing resilience in the face of global economic pressures, including the impact of US tariff hikes, while Taiwan pledges to address trade barriers with the US.
Regional Cooperation and International Relations: Saudi Arabia is engaging in discussions with the US on regional security and collaborating with GCC nations and the EU on nuclear safety and radiation data exchange.
Humanitarian Concerns and Conflict in the Region: The ongoing conflict in Gaza and its impact on civilians and journalists are highlighted, along with international efforts to provide aid and calls for a ceasefire.
Domestic Initiatives and Social Progress: The Kingdom is launching various initiatives focused on supporting people with autism, developing historical mosques, combating illegal residency, celebrating volunteerism, and empowering women.
Cultural Preservation and Innovation: Saudi Arabia is emphasizing the importance of handicrafts as a cultural and economic resource and highlighting cultural events and intellectual discourse.
Efforts Against Misinformation: The dangers of rumors and fake news are addressed, along with Saudi Arabia’s efforts to combat their spread.
Commemoration of Prominent Figures: The passing of Dr. مطلب النفيسة, a significant figure in Saudi law and the Shura Council, is noted, reflecting on his contributions.
Housing and Land Initiatives: A new policy aiming to make land more affordable for young Saudis is introduced, seen as a major step towards social and economic stability.
Most Important Ideas and Facts:
1. Saudi Arabia’s Focus on Healthcare Advancement:
World Health Day Participation: Saudi Arabia actively participates in World Health Day (April 7th), emphasizing raising health awareness and facilitating access to healthcare services for all segments of society.
Quote: “اململكة تشارك العالم ممثلة بوزارة الصحة بيوم الصحة العالمي الذي يصادف 7 أبريل من كل عام” (The Kingdom participates with the world, represented by the Ministry of Health, in World Health Day, which falls on April 7th of each year).
Health Sector Transformation Program: This program is a key initiative to achieve Vision 2030, aiming to develop a comprehensive, effective, and sustainable healthcare system with a focus on prevention.
Quote: “التحول الصحي برنامج يعد لتحقيق رؤية 2030، ويهدف إلى تطوير منظومة الرعاية الصحية لتكون شاملة، فعالة، ومستدامة، مع التركيز على الوقاية أكثر من العلاج” (The Health Transformation Program is considered one of the executive programs to achieve Vision 2030, and it aims to develop the healthcare system to be comprehensive, effective, and sustainable, with a focus on prevention more than treatment).
Key Objectives of Healthcare Transformation: Improving the quality and efficiency of health services, ensuring fair and easy access, promoting prevention, improving financial resource management, and digital transformation.
“Wasfati” Service: The Ministry of Health launched the “Wasfati” (My Prescription) service to facilitate electronic access to medications, reduce reliance on paper prescriptions, and improve the patient experience.
2. Economic Developments and Market Reactions:
TASI Market Rebound: The Saudi stock market index “TASI” rebounded during trading on Monday, April 7, 2025, recovering some of its losses. Experts believe this indicates the market is beginning to absorb recent pressures, including the impact of potential US tariff hikes.
Quote: “ارتد مؤشر السوق السعودي «تاسي» في منتصف تعاملات جلسة يوم أمس الاثنين 7 أبريل 2025 بنسبة ارتفاعًا للسوق العام المؤشر ليسجل 11،168.78 نقطة” (The Saudi market index “TASI” rebounded in the middle of yesterday, Monday, April 7, 2025 trading session with an increase for the general market index to record 11,168.78 points).
Sector Performance: The telecommunications, energy, basic materials, and banking sectors saw increases during the trading session.
Taiwan’s Response to US Tariffs: Taiwan considers the new 32% US tariffs on its imports (excluding semiconductors and some transportation equipment) “completely unreasonable” and pledges to remove trade barriers with the US and consider retaliatory measures.
Quote: “تايوان وصفت المواصلات، أشباه باستثناء التي تعد جزءًا من تغير جذري في الممارسات التجارية الأمريكية، بأنها «غير معقولة تمامًا»” (Taiwan described transportation, excluding semiconductors, which is considered part of a radical change in American trade practices, as “completely unreasonable”).
3. Regional Cooperation and International Relations:
Defense Minister Discusses Regional Issues with US Counterpart: The Saudi Minister of Defense received a phone call from the US Secretary of Defense, Lloyd Austin, to discuss the development of regional situations and efforts to support the security and stability of both countries and the region.
Quote: “تلقى صاحب السمو الملكي الأمير خالد بن سلمان بن عبدالعزيز وزير الدفاع اتصالاً هاتفيًا من معالي وزير الدفاع الأمريكي بيت هيغسيث. وجرى خلال الاتصال استعراض العلاقات الدفاعية السعودية الأمريكية، وآفاق التعاون في المجال العسكري، وبحث تطورات الأوضاع الإقليمية ورؤية تجاهها، والجهود المبذولة من البلدين الصديقين لدعم أمن البلدين واستقرار المنطقة والعالم” (His Royal Highness Prince Khalid bin Salman bin Abdulaziz, Minister of Defense, received a telephone call from His Excellency the US Secretary of Defense, Pete Hegseth. During the call, the Saudi-American defense relations were reviewed, prospects for cooperation in the military field were discussed, and the developments in the regional situations and the vision towards them, as well as the efforts made by the two friendly countries to support the security of the two countries and the stability of the region and the world, were discussed).
GCC-EU Radiological Data Exchange: The GCC and the EU are establishing a platform for exchanging radiological data (GCC-RDEP) to limit the effects of radiological and nuclear disasters.
Quote: “دشن معالي الأمين العام لمجلس التعاون لدول الخليج العربية الأستاذ جاسم محمد البديوي، مشروع منصة تبادل البيانات الإشعاعية بين دول المجلس ومركز السلامة النووية وإدارة الطوارئ المشترك” (His Excellency the Secretary-General of the Cooperation Council for the Arab States of the Gulf, Professor Jassim Mohammed Al-Budaiwi, inaugurated the project of a platform for the exchange of radiological data between the member states of the Council and the Joint Nuclear Safety and Emergency Management Center).
4. Humanitarian Concerns and Conflict in the Region:
Journalists Killed in Gaza: The number of journalists killed since the start of the “genocidal war” on the Gaza Strip has risen to 127 with the death of Hafeez Al-Faqawi in Khan Yunis.
Quote: “ارتفع عدد الشهداء الصحفيين إلى (127 صحفيًا) منذ بدء حرب الإبادة الجماعية على قطاع غزة” (The number of martyred journalists has risen to (127 journalists) since the beginning of the genocidal war on the Gaza Strip).
Egyptian and French Presidents Reject Displacement of Gazans: President Sisi of Egypt and President Macron of France reiterated their rejection of forcibly displacing Palestinians from the Gaza Strip and affirmed their support for rebuilding the sector and urgently delivering humanitarian aid.
Quote: “الرئيسان السيسي والفرنسي إيمانويل ماكرون من السكان لترحيل رفضهما الاثنين العربية للخطة ودعمهما قسرًا غزة السيسي وقال للقطاع إعمار الإعادة «تناولت بالقاهرة صحفي مؤتمر في معمق بشكل ماكرون والرئيس الساحة على المتلاحقة التطورات بحثا الإقليمية والدولية وعلى رأسها الوضع المأساوي في قطاع غزة، حيث أكدنا ضرورة العودة إلى وقف إطلاق النار فوري، بشكل عاجل، بشكل كامل» الإنسانية المساعدات بإدخال والسماح” (The presidents Sisi and the French Emmanuel Macron affirmed their rejection of the transfer of residents on Monday, their support for the Arab plan, and the forced transfer from Gaza. Sisi said regarding the reconstruction of the sector, “I discussed in depth during a press conference in Cairo with Macron, the successive developments on the regional and international scene, at the forefront of which is the tragic situation in the Gaza Strip, where we affirmed the necessity of returning to an immediate ceasefire, urgently, completely,” and “allowing the entry of humanitarian aid”).
5. Domestic Initiatives and Social Progress:
Prince of Jazan Launches Autism Awareness Campaign: The Prince of Jazan launched a campaign by the Sultan bin Abdulaziz Al Saud Charity Foundation for Autism, aiming to raise awareness, enhance services, and support training and inclusion programs.
Quote: “دشن صاحب السمو الملكي الأمير محمد بن ناصر بن عبدالعزيز، أمير منطقة جازان، صباح أمس حملة الأمير سلطان بن عبدالعزيز للتوحد” (His Royal Highness Prince Mohammed bin Nasser bin Abdulaziz, the Prince of Jazan region, inaugurated yesterday morning the Prince Sultan bin Abdulaziz campaign for autism).
Second Phase of Historical Mosque Development Launched in Riyadh: The second phase of a project to develop historical mosques has been launched in Riyadh, following the completion of the first phase which included the restoration of 30 mosques in 10 regions.
Campaign Against Illegal Residency: Authorities in Saudi Arabia have apprehended a significant number of individuals violating residency, border security, and labor regulations.
“Absher with Eid” Initiative Benefits 2000: The “Absher with Eid” volunteer initiative concluded, having provided aid during Eid al-Fitr in several regions of Saudi Arabia.
Princess Nourah University Organizes “Saudi Women in Development” Conference: The conference aims to highlight the role of Saudi women in building a prosperous future in line with Vision 2030 and to discuss empowerment policies and initiatives.
6. Cultural Preservation and Innovation:
2025 Declared “Year of Handicrafts”: The Ministry of Culture has announced 2025 as the “Year of Handicrafts” to revive and promote the Kingdom’s rich craft heritage as a cultural and economic resource.
Quote: “أعلنت وزارة الثقافة أن عام 2025 سيكون عامًا مخصصًا لإحياء الحرف اليدوية، تحت عنوان «عام الحرف اليدوية»، في مبادرة وطنية تهدف إلى إحياء التراث الحرفي الغني الذي تفخر به المملكة، وتحويله من موروث رمزي إلى مورد اقتصادي نابض بالحياة” (The Ministry of Culture announced that the year 2025 will be a year dedicated to the revival of handicrafts, under the title “Year of Handicrafts,” in a national initiative aimed at reviving the rich craft heritage that the Kingdom is proud of, and transforming it from a symbolic heritage into a vibrant economic resource).
“Ithra” Celebrates Eid with Cultural and Entertainment Activities: The King Abdulaziz Center for World Culture (“Ithra”) attracted a large number of visitors during Eid with various cultural and interactive programs, including a video game music performance.
Asilah Cultural Festival Announces Spring Edition: The international Asilah Cultural Festival in Morocco launched its spring edition dedicated to visual arts, featuring exhibitions and workshops with artists from various countries.
7. Efforts Against Misinformation:
Awareness Campaigns Against Rumors: Saudi Arabia is actively working to combat the spread of false news and rumors, recognizing their threat to social harmony and security. The Public Prosecution emphasizes the legal penalties for spreading misinformation online.
Quote: “تعد الأخبار الكاذبة والإشاعات بذورًا مغروسة وهي من أخطر السلوكيات التي تهدد السلم المجتمعي إذ ينتج عنها القلق والخوف المؤدي إلى زعزعة الأمن والاستقرار” (False news and rumors are embedded seeds and are among the most dangerous behaviors that threaten social harmony, as they result in anxiety and fear leading to the undermining of security and stability).
Qassim Region Holds Seminars to Combat Rumors: The Qassim region has organized several seminars in recent years to raise awareness about the dangers of rumors and discuss ways to confront them from a Sharia, social, and security perspective.
8. Commemoration of Prominent Figures:
Passing of Dr. مطلب النفيسة: The article mourns the passing of His Excellency Dr. مطلب bin Abdullah Al-Nafisah, a former Minister of State, member of the Shura Council, and a significant figure in Saudi law. His contributions to the development of laws and his character are praised.
Quote: “أشهد الله سبحانه وتعالى أن يرحمك أبا خالد أيها الأستاذنا الدكتور مطلب بن عبدالله النفيسة، أبا خالد فقد ملكت قلب كل من عرفك وتعامل معك” (I call upon Allah Almighty to have mercy on you, Abu Khalid, our teacher Dr. مطلب bin Abdullah Al-Nafisah, Abu Khalid, you have captured the heart of everyone who knew you and dealt with you).
9. Housing and Land Initiatives:
Land Price Ceiling for Young Saudis: A decision has been made to set a maximum price for land at 1500 riyals to make it more affordable for young Saudis, a move seen as a significant step towards enabling homeownership and achieving social stability.
Quote: “جاء قرار تحييد الأراضي وتحديد الحد الأقصى للسعر عند 1500 ريال ليشكل تحولًا كبيرًا في مسار تملك الأراضي للشباب السعودي” (The decision to neutralize lands and set the maximum price at 1500 riyals came to represent a major shift in the path of land ownership for Saudi youth).
Royal Commission for Riyadh to Provide Affordable Housing Land: The Royal Commission for Riyadh will provide tens of thousands of residential plots annually at prices not exceeding 1,500 riyals per meter.
Overall Significance:
These articles collectively highlight Saudi Arabia’s proactive approach to various domestic and international challenges and its commitment to Vision 2030. The focus on healthcare development, economic resilience, regional cooperation, social progress, cultural preservation, and addressing societal issues like misinformation underscores the Kingdom’s multifaceted development agenda. The new land policy is a particularly significant development with potential long-term social and economic benefits for young Saudis.
Saudi Arabia & Global Updates: Vision 2030, Trade, & Health
FAQ: Key Themes and Ideas from the Provided Sources
1. What are the main objectives of Saudi Arabia’s Vision 2030 in the healthcare sector, as highlighted in the article about World Health Day? Saudi Arabia’s Vision 2030 aims to transform the healthcare system into one that is comprehensive, effective, and sustainable. The key objectives include improving the quality and efficiency of healthcare services, ensuring fair and easy access to health services for all segments of the population, promoting preventive care to reduce health risks, enhancing the quality of life, improving the management of financial resources in the health sector, and fostering digital transformation through initiatives like the “Wasfaty” (My Prescription) service.
2. How did the Saudi stock market (“TASI”) react to the news of potential US tariff increases, and what does this indicate about the market’s resilience? Initially, the Saudi stock market (“TASI”) experienced a significant drop following the news of potential US tariff increases, reflecting concerns about the broader global economic impact. However, the market showed a notable rebound during the same trading session, recovering a portion of its losses. This recovery suggests that the Saudi market has begun to absorb the external pressures and that the underlying strength of the national economy, driven by the achievements of Vision 2030, provides a degree of resilience against global shocks.
3. What is the significance of the data exchange agreement between GCC countries and the European Union regarding radiation monitoring? The data exchange project between the GCC-RDEP (GCC Center for Radiological Data Exchange and Emergency Management) and the European Union signifies a crucial step towards enhancing nuclear safety and security in both regions. It aims to limit the effects of radiological and nuclear disasters by facilitating the exchange of radiation monitoring data and enabling early detection and analysis of potential threats. This collaboration allows for the use of advanced simulation systems to predict potential consequences and provide timely technical recommendations to decision-makers in GCC countries.
4. What were the key topics discussed during the phone call between the Saudi Minister of Defense and the US Secretary of Defense? The phone call between the Saudi Minister of Defense and the US Secretary of Defense focused on reviewing the strategic relationship between the two countries in the defense field, exploring avenues for cooperation, and discussing the latest developments in regional affairs and shared perspectives on them. They also addressed mutual efforts to support the security and stability of both nations, the region, and the world, in addition to other issues of common interest.
5. What are Taiwan’s concerns and responses to the potential imposition of new tariffs by the United States? Taiwan views the potential imposition of new tariffs by the United States as “completely unreasonable” and anticipates significant harm to American consumers due to the vital role Taiwanese imports, particularly semiconductors, play in the US supply chain. In response, Taiwan has pledged to remove trade barriers with the US, encouraged Taiwanese companies to increase investments in the United States, and is considering retaliatory measures. The Taiwanese government is also planning financial aid and relief measures for affected industries.
6. What are the primary goals of Saudi Arabia’s “Year of Handicrafts 2025” initiative? The “Year of Handicrafts 2025” initiative in Saudi Arabia is a national project aimed at reviving the rich heritage of handicrafts in the Kingdom. Its primary goals include empowering male and female artisans across the country by providing financial and moral support, creating a sustainable environment that enhances their role in the national economy, and building a thriving cultural sector that contributes to economic diversification, in line with the objectives of Saudi Vision 2030. The initiative seeks to transform traditional crafts from symbolic heritage into a vibrant economic resource.
7. What are the main features and objectives of the “Wasfaty” (My Prescription) service launched by the Saudi Ministry of Health? “Wasfaty” (My Prescription) is a digital service launched by the Saudi Ministry of Health to facilitate patients’ access to medications electronically. It aims to enhance the efficiency and quality of healthcare, reduce reliance on paper prescriptions, improve medication adherence, and minimize medical errors related to prescriptions. The service allows doctors to issue prescriptions electronically, which are then automatically sent to the nearest participating pharmacy, enabling patients to collect their medication without needing to return to the healthcare facility.
8. What efforts is Saudi Arabia undertaking to combat epidemics and infectious diseases? The Saudi Ministry of Health is making significant efforts to combat epidemics and infectious diseases through national campaigns and programs targeting all age groups. These include comprehensive vaccination programs for children against diseases like diphtheria, measles, polio, whooping cough, tetanus, hepatitis B, influenza, and others. The Ministry also implements mandatory vaccinations for Hajj and Umrah pilgrims and intensifies national awareness campaigns for prevention, such as vaccination drives against HPV. These efforts reflect a strategic approach to protect the community and prevent the spread of infectious diseases.
Saudi Arabia: Enhancing the Health Sector
Based on the sources, Saudi Arabia is actively engaged in enhancing its health sector through various initiatives and programs.
Key aspects of the Saudi health sector highlighted in the sources include:
Commitment to Universal Healthcare: The Kingdom participates in the global celebration of World Health Day on April 7th each year, an event initiated by the World Health Assembly in 1950 to commemorate the founding of the World Health Organization in 1948. Saudi Arabia organizes awareness events and programs aiming to facilitate access to health services for all segments of society.
Focus on Awareness and Prevention: There is a strong emphasis on raising awareness about the importance of health and its connection to economic and environmental factors. Activities are held in health and educational facilities like universities and medical centers, offering advice on healthy nutrition, the importance of exercise, and sufficient fluid intake, along with educational consultations. The Kingdom is also actively combating smoking through intensified awareness efforts during Ramadan, organized by the Qassim Health Cluster. These campaigns involve organizing awareness corners and exhibitions in public places to highlight the health, economic, and social risks associated with smoking and electronic cigarettes. Furthermore, the Ministry of Health is making significant efforts in combating epidemics and infectious diseases through national programs and campaigns targeting all age groups, including comprehensive vaccination programs for children.
Specific Health Initiatives and Programs:”Wafi” and “Tashafi” services: These services, linked to the Ministry of Health and the Saudi Food and Drug Authority (SFDA), aim to ensure the safe and proper use of medication. “Wafi” allows for electronic prescription verification, while “Tashafi” enables monitoring and follow-up of medication use, including reminders about doses and appointments. These services also aim to reduce crowding at hospital pharmacies.
Expanded Immunization Program: This program provides vaccinations for children against various diseases like diphtheria, measles, whooping cough, tetanus, hepatitis B, Haemophilus influenzae type b, rotavirus, and pneumococcal infections.
Vaccination Campaigns for Pilgrims: The Ministry of Health mandates vaccines for Hajj and Umrah pilgrims, such as meningitis and seasonal influenza vaccines, to protect them from potential epidemics.
National Awareness Campaigns: These campaigns focus on preventing the spread of epidemics and promoting awareness about diseases like HPV.
Psychological Support: Initiatives aim to improve public health and enhance psychological well-being among individuals and the community.
Anti-Smoking Campaigns: The Ministry of Health, along with health clusters like the Qassim Health Cluster, intensifies efforts to combat smoking through awareness programs and exhibitions.
Support for Autism: The Prince Sultan bin Abdulaziz Campaign for Autism was launched in the Jazan region to raise awareness, enhance services for individuals with autism and their families, and support training and inclusion programs.
Development of Healthcare Infrastructure and Services: The Kingdom is focused on developing the healthcare system effectively and sustainably, with an emphasis on prevention. This includes leveraging technology, as seen in the development of the “Sehaty” application.
International Cooperation: The Gulf Cooperation Council (GCC) and the European Union are collaborating on a project to exchange radiological data between the GCC Center for Radiological Data Exchange (GCC-RDEP) and the Joint Research Centre for Nuclear Safety and Security, to manage emergency situations.
Hospital Achievements: Dr. Sulaiman Al Habib Hospital at Takhassusi successfully treated a sixty-year-old patient who was paralyzed due to a rare cancerous tumor in her chest that extended to her back.
Focus on Public Health: Public health is a priority, with programs aimed at promoting healthy lifestyles, preventing diseases, and maintaining a healthy environment.
Overall, the sources indicate a proactive and multi-faceted approach by Saudi Arabia to improve the health and well-being of its population through awareness campaigns, preventative measures, the development of health services and infrastructure, and international collaborations.
Saudi Arabia Real Estate: Regulations, Market Shifts, and Riyadh Platform
Based on the sources, the real estate market in Saudi Arabia is currently undergoing changes and developments. One article notes that the real estate market is expected to witness scrutiny due to new regulations. During this period of change, some individuals are reportedly exploiting the situation by raising rental values for both residential and commercial properties, which is creating additional pressure on citizens, residents, and commercial tenants.
However, another perspective from the sources indicates that these new regulations, when properly implemented, are anticipated to foster a balance between supply and demand. This balance is predicted to have a positive impact on the stability of the real estate market itself.
Furthermore, there is an active initiative to develop the real estate sector in Riyadh. The Riyadh governorate is currently working on creating a specialized electronic platform for the real estate sector. This platform aims to directly receive land requests from citizens, eliminating the need for intermediaries or external parties. The goal is to streamline the process for citizens seeking land in the Riyadh area.
It is also important to note a caution mentioned in the sources regarding unofficial claims related to land grants. The authorities have emphasized that any updates or details concerning the electronic platform or land allocation procedures will be announced through official channels of the Riyadh governorate and the relevant authority related to health. The public is urged to obtain information only from official sources and to be vigilant against any fraudulent attempts that claim to offer land grants outside the official regulatory framework.
Trump’s Tariffs and Trade Policies: Global Implications
Based on the sources, there is discussion regarding US tariffs, particularly those imposed by Donald Trump.
One article states that a “double whammy” of customs duties imposed by Trump under the name “Liberation Day” on April 2nd, combined with OPEC+ increasing its production on April 3rd, led to a sharp drop in oil prices. These reciprocal customs duties ranged from 10% to 54%. This article also mentions that the US is displeased with the trade surplus with Taipei, which reached $74 billion. Dr. Fahad Mohammed bin Juma’h argues that these policies, including the new tariffs, could lead to a new inflationary wave and slow down economic growth and trade disputes, potentially pushing the global economy into stagflation.
Furthermore, source indicates that if negotiations with partners regarding tariffs do not result in an agreement, Trump threatens to intensify sanctions, alongside efforts to reduce the trade surplus with Venezuela. The article also notes that analysts anticipate the US Federal Reserve to lower interest rates five times this year, which could influence oil prices as the dollar weakens.
Additionally, source mentions that US President Donald Trump informed foreign governments that they would need to pay “large amounts” for the “comprehensive, customs duties”, which he referred to as “medicine”.
Source states that Trump’s administration informed officials in Baghdad that if measures were not taken to resolve certain issues, their territory might be targeted by US airstrikes.
In summary, the sources highlight Trump’s imposition of significant customs duties, his dissatisfaction with trade surpluses, and his willingness to use tariffs and sanctions as leverage in international relations. The potential consequences of these tariff policies, such as inflation, slowed economic growth, and trade disputes, are also mentioned.
Al-Aqsa Mosque: Settler Rituals and Palestinian Response
Based on the sources, the discussion surrounding Al-Aqsa Mosque centers on attempts by settlers to conduct religious rituals within its premises. Palestinian religious and national bodies have issued urgent calls to gather as many people as possible at Al-Aqsa Mosque, particularly in the days leading up to the “Passover” holiday. This mobilization is aimed at confronting the plans of settlers and preventing any attempts to bring offerings into the mosque or storm its courtyards.
Furthermore, one source, while primarily discussing the Ibrahimi Mosque in Hebron, mentions that the attacks by settlers, especially at Al-Aqsa Mosque, are part of a systematic effort to gradually transform the Ibrahimi Mosque into a Jewish synagogue. This suggests a broader concern about the encroachment on and potential alteration of Islamic holy sites by settlers.
King Salman Relief: Absence in Provided Sources
Based on the provided sources, there is no direct discussion or mention of “King Salman Relief”.
While the sources do discuss various charitable initiatives and humanitarian efforts within Saudi Arabia, such as the Prince Sultan bin Abdulaziz Campaign for Autism launched in the Jazan region, and the “Absher Bel Eidiyah” initiative by a volunteer association, there is no specific information provided about any relief efforts explicitly named or attributed to King Salman.
Main Headings
وزير الدفاع يبحث مع نظيره الأميركي تطورات الأوضاع الإقليمية The Minister of Defense discusses regional developments with his American counterpart.
السوق العقاري يترقب الأنظمة الجديدة The real estate market is awaiting new regulations.
يوم الصحة العالمي.. المملكة تعزز الوعي World Health Day: The Kingdom raises awareness
تبادل البيانات الإشعاعية بين دول «الخليجي» والاتحاد الأوروبي Exchange of radiation data between the Gulf countries and the European Union
تاسي» استوعب صدمة الرسوم الأميركية Tasi absorbed the shock of the US tariffs
استشهاد 210صحفيين في قصف إسرائيلي 210 journalists killed in Israeli bombing
تايـوان تتعهد إزالـة الحواجز التجارية مع أميـركا Taiwan pledges to remove trade barriers with the US
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
These excerpts provide a comprehensive introduction to Python programming concepts. They cover fundamental data types like numbers, strings, tuples, lists, dictionaries, and sets, explaining their properties and operations. The text also explores essential programming structures such as variables, operators, conditional statements, loops, functions (including predefined, user-defined, anonymous, and recursive), modules, packages, and exception handling. Finally, it touches upon file handling for various data formats and introduces the basics of object-oriented programming, including classes, objects, methods, inheritance, and polymorphism.
Python Basics and Data Structures Study Guide
Quiz
Explain the concept of a variable in Python. How does Python handle data types for variables?
What are the key differences between the core numeric data types in Python: integer, float, and complex?
Describe the characteristics of a string in Python. What does it mean for a string to be immutable?
Explain the concept of indexing and slicing in Python sequences (like strings, lists, and tuples). Provide a brief example.
What are the primary differences between a list and a tuple in Python? When might you choose to use one over the other?
Describe the structure of a dictionary in Python. How are elements accessed in a dictionary?
What is a set in Python, and what are its key properties? How does it differ from a list?
Explain the purpose of the if, elif, and else statements in Python. How do they control the flow of execution?
Describe the functionality of a for loop in Python. How is it used to iterate over sequences?
What is a function in Python? How do you define and call a function?
Quiz Answer Key
A variable in Python is a named storage location that holds a value. Python is dynamically typed, meaning you don’t need to explicitly declare the data type of a variable; the interpreter infers the type based on the value assigned to it.
Integers (int) are whole numbers without a decimal point. Floats (float) are numbers with a decimal point. Complex numbers (complex) have a real and an imaginary part, represented in the form a+bj.
A string in Python is an ordered sequence of characters enclosed in quotes (single or double). Immutability means that once a string is created, its individual characters cannot be changed directly. Any operation that appears to modify a string actually creates a new string.
Indexing allows you to access individual elements in a sequence using their position (starting from 0). Slicing allows you to extract a subsequence of elements using a start index, an end index (exclusive), and an optional step. Example: my_list = [10, 20, 30, 40]; print(my_list[1]) (output: 20), print(my_list[1:3]) (output: [20, 30]).
A list is a mutable, ordered sequence enclosed in square brackets, allowing for element modification, addition, and removal. A tuple is an immutable, ordered sequence enclosed in parentheses, meaning its elements cannot be changed after creation. Tuples are often used for fixed collections of items.
A dictionary in Python is an unordered collection of key-value pairs enclosed in curly braces. Each key must be unique and immutable, and it is used to access its corresponding value. Elements are accessed using their keys within square brackets, e.g., my_dict[‘key’].
A set in Python is an unordered collection of unique elements enclosed in curly braces. Sets automatically remove duplicate entries and support mathematical set operations like union, intersection, and difference. Unlike lists, sets do not maintain the order of elements and cannot be indexed directly.
The if statement executes a block of code if a specified condition is true. The elif (else if) statement checks an additional condition only if the preceding if or elif condition was false. The else statement executes a block of code if none of the preceding if or elif conditions were true.
A for loop in Python is used to iterate over each item in a sequence (such as a list, tuple, string, or range) or other iterable object. It executes a block of code for each item in the sequence. Example: for item in my_list: print(item).
A function in Python is a block of reusable code that performs a specific task. It is defined using the def keyword followed by the function name, parentheses for parameters (optional), and a colon. A function is called by using its name followed by parentheses, potentially passing arguments.
Essay Format Questions
Discuss the importance of data structures in Python. Compare and contrast the use cases for lists, tuples, dictionaries, and sets, providing specific examples where each would be most appropriate.
Explain the concepts of mutability and immutability in Python, focusing on how these properties affect the behavior and usage of different data types like strings, lists, and tuples.
Describe the role of control flow statements (conditional statements and loops) in Python programming. Illustrate with examples how if/elif/else and for loops can be used to solve common programming problems.
Discuss the benefits of using functions in Python. Explain the process of defining and calling functions, and elaborate on the concepts of function parameters and return values.
Imagine you are developing a program to manage a small library. Describe how you might use various Python data structures (lists, dictionaries, sets, tuples) to store and manipulate information about books and borrowers.
Glossary of Key Terms
Variable: A named storage location that holds a value in memory.
Data Type: The classification of data that specifies which type of value a variable can hold and what types of operations can be performed on it (e.g., integer, string, list).
Integer (int): A whole number without a decimal point.
Float (float): A number with a decimal point.
String (str): An ordered sequence of characters.
Immutable: A property of an object whose state cannot be modified after it is created.
Mutable: A property of an object whose state can be modified after it is created.
Index: The position of an element within a sequence, starting from 0.
Slicing: A way to extract a subsequence of elements from a sequence using a range of indices.
List (list): A mutable, ordered sequence of items enclosed in square brackets.
Tuple (tuple): An immutable, ordered sequence of items enclosed in parentheses.
Dictionary (dict): A mutable, unordered collection of key-value pairs enclosed in curly braces.
Set (set): A mutable, unordered collection of unique elements enclosed in curly braces.
Conditional Statement: A statement that executes a block of code based on whether a condition is true or false (if, elif, else).
Loop: A control flow statement that allows code to be executed repeatedly (for, while).
Function: A block of organized, reusable code that performs a specific task.
Parameter: A variable listed inside the parentheses in the function definition.
Argument: The actual value that is passed to a function when it is called.
Return Value: The value that a function sends back to the caller after it has executed.
Module: A file containing Python definitions and statements (with a .py extension).
Package: A directory that contains multiple Python modules and an __init__.py file, used to organize modules.
Identifier: A name used to identify a variable, function, class, module, or other object.
Keyword: A reserved word that has a special meaning in Python and cannot be used as an identifier.
Indentation: The spaces or tabs used at the beginning of a code line to define blocks of code in Python.
Operator: A symbol that performs an operation on one or more operands (e.g., +, -, *, /, ==, >).
Operand: The value or variable on which an operator acts.
Expression: A combination of variables, operators, and values that evaluates to a single result.
Statement: A complete line of code that performs an action.
String Formatting: The process of embedding expressions inside string literals.
Escape Sequence: A sequence of characters that represents a special character (e.g., \n for newline, \t for tab).
Raw String: A string literal prefixed with r or R, where backslashes are treated as literal characters.
Concatenation: The operation of joining two or more strings or other sequences together.
Repetition: The operation of repeating a string or other sequence multiple times.
Method: A function that is associated with an object of a particular class.
Class: A blueprint for creating objects, defining their attributes (data) and methods (behavior).
Object: An instance of a class.
Recursion: A programming technique where a function calls itself.
Anonymous Function (Lambda): A small, unnamed function defined using the lambda keyword.
Exception Handling: A mechanism to deal with runtime errors gracefully using try, except, else, and finally blocks.
File Handling: The process of reading from and writing to files.
Mode (File Handling): A string indicating how a file is opened (e.g., ‘r’ for read, ‘w’ for write, ‘a’ for append).
Pickle: A Python module used for serializing and de-serializing Python object structures.
JSON: A lightweight data-interchange format.
CSV: Comma Separated Values, a file format for storing tabular data.
OS Module: A built-in Python module that provides a way of using operating system dependent functionality.
Path (File System): A string that specifies the location of a file or directory in a file system.
Briefing Document: Review of Python Basics and Data Types
This briefing document summarizes the main themes and important ideas discussed in the provided source “01.pdf,” which covers fundamental concepts in Python programming, including variables, data types, operators, control flow (conditional statements and loops), functions, modules and packages, exception handling, file handling, and the OS module.
1. Variables and Data Types:
Variables as Memory Allocation: A variable in Python is essentially a named memory location used to store data. Each variable has an identification number (obtained using the id() function) that represents its memory address.
“variable is nothing but a memory allocation if it’s a memory allocation which store the data that means it release some identification number as well so we can easily find it out like a ID there is the ID function where find it out the identification number when I pass ID of a so you can see here this is the ident identification number”
Data Type Dependency on Memory ID: The identification number (memory address) allocated to a variable can depend on its data type. Variables with different data types are likely to have significantly different ID numbers.
“reason we change the data type so it release the memory allocation memory uh ID depend on their data type if I’m taking the different data type the that will also be number D is equal to 19 + 19.8 and check the ID of D that will be the uh different identification number it’s not only the few digit is change so lots of values change also reason we change the data type because the D is a floating data type”
Main Categories of Data Types: Python has several built-in data types categorized as:
Numeric: Integer (int), Complex, Float (float).
“numeric dictionary Boolean set and sequence type where we have the main data type is a integer complex and Float integer complex and Float”
Dictionary: Key-value pairs.
“if I Define the same value with key value pair is equal to key value pair like 5 colon 4 uh 4 colon 7 and 9 colon 8 so if you define like this that will be considered as a dictionary”
Boolean: True or False.
“dictionary bullan set is also there”
Set: Unordered collection of unique elements.
“if I Define with the curly brasses curly brasses directly passing the values that is considered as a set”
Sequence Type: Ordered collections:
String (str): Sequence of characters enclosed in single or double quotes.
“if I’m defining with a double quotes so like hello here so that’s a string data type”
List (list): Ordered, mutable sequence of items enclosed in square brackets.
“you define B is equal to in square bracket that will consider as a that will consider as a list”
Tuple (tuple): Ordered, immutable sequence of items enclosed in round brackets.
“if I Define with a round bracket that will be considered as a tle”
Comments: The hash symbol (#) is used to denote comments in Python code, which are ignored by the interpreter.
“what exactly the mean of this hash this hash symbol is nothing but a comment we are defining as a comment”
2. Keywords:
Reserved Words: Keywords are reserved words in Python that have specific meanings and cannot be used as identifiers (variable names, function names, class names).
“keyword is reserve word which used for one specific purpose fake purpose cannot be used as a identifier cannot be used as a identifier now the question is what exactly the mean of identifier let me make as a uh markdown so that markdown in the sense it will taking one statement it will not consider as a code okay normal statements so cannot be used as a identifier so what is the identifier identifier so identifier in the sense any variable name any um you know uh function name okay any variable name any function name any class name that will be consider as a identifier class name that will be considered as a identifier”
Checking Keywords: The keyword module provides access to the list of Python keywords. keyword.kwlist returns a list of all keywords.
“there is one module is called as keyword module keyword module keyword module and when you pass it here keyword do KW list then you’ll find it out how many keyword is available for false none true the lots of keyword is available is Lambda lots of keyword is there which is stored with a square bracket one container and that container we are calling list”
Number of Keywords: The number of keywords can vary between Python versions. In the described context (likely Python 3.9), there are 35 keywords.
“when I run it will showing you 30 five keyword is available okay so whenever you using any uh ideally right now I’m using the Jupiter notebook ideally so that time you can easily check it”
Identifier Restrictions: Attempting to use a keyword as an identifier will result in a syntax error.
“can I use uh any keyword like uh if I’m using if Okay small i f if we are using IF is equal to 8 can I define it like this no it will giving the error because because this if is reserved for only the conditional statement you can’t use as a identifier you can’t use as a normal variable”
3. Indentation:
Block Definition: Indentation (using whitespace, typically four spaces in Jupiter Notebook and PyCharm) is crucial in Python to define code blocks, such as the body of conditional statements (if, elif, else) and loops.
“indentation in the sense is Define the block I have some program uh like if program uh conditional statement program if a is greater than let me first Define it a is equal to 9 and B is equal to 8 and I have a program is if a is greater than b okay so in other programming language we are using the curly brasses and put inside a statements so here curly brasses is not acceptable so we have a indentation we have to use a colon after the colon it automatically taking the four space okay automatically taking the four space”
Block Scope: Statements within the same indented block are considered part of that block. Changes in indentation signify the beginning or end of a block.
“if I’m writing here the hello okay so if you want to Define anything like hello if I’m writing here and hi if I’m writing here and he if I’m writing here print he okay this hello hi hey yeah we can say line number 5 six 7 that’s comes in if block so defining the block we are using if uh colon and automatically taking the for space if you’re using the back space and write it down here print by so that line number nine will consider as a uh outside of the block so that bu is not in if condition okay by is not in if condition”
4. Input and Output:
input() Function: The input() function is used to obtain user input from the console. It always returns the input as a string.
“we have another function is input function input function will always take the input as a string”
Type Conversion: To treat the input as a different data type (e.g., integer), type conversion functions like int(), float(), etc., must be used.
“so cannot be multiplied with string and integer so we have another function is int so likewise other data type like int float complex we have a function as well I’m using int open the bracket and close it here when I run it it asking the question enter the value of x I’m passing here five then it will be calculate and showing the answer is five”
print() Function: The print() function is used to display output to the console. Multiple items can be printed in a single print() statement by separating them with commas.
“result is is nothing but your double uh statements or string and is your number so we have to separate it with a comma when I run it asking the question enter the value of x 6 so um sorry not to display uh X we have to display y let me run it again enter the value of X4 and accordingly is getting the answer is 17”
5. Operators:
Definition: Operators are symbols that perform operations on operands (values or variables).
“operator is nothing but the symbol which is responsible to do any operations for example I have a five + 7 so the plus is a responsible to do addition operation so this one we can say it’s operator this one is operator and five and seven is called as a operant operants”
Categories of Operators: Python supports various categories of operators:
“the first one is arithmetic operator as I said that the symbol are available plus minus the star so I think you guys is already aware about that so the meaning of the plus is nothing but using for addition minus is for subtraction so we can directly use this kind of symbol so only this double star uh modulo that percentage symbol and double slash is something new for you”
Assignment Operators: Used to assign values to variables (e.g., =, +=, -=, *=, /=, etc.).
“assignment operator”
Relational (Comparison) Operators: Used to compare values and return a Boolean result (>, <, >=, <=, == (equal to), != (not equal to)). Also referred to as comparison or conditional operators.
“third operator is a relation relational operator somebody is also calling the comparison operator because you are comparing a isal to 5 is there b is equal to 7 is there if you’re writing a greater than b you can also write B is less than a that means you are comparing the answer is always The Logical format what is a logical logical format can be true can be false true or false answer right your answer will always be the true and false concept you comparing like a is less than b a is greater than or equal to B this is the symbol for not equal to this symbol for not equal to this is symbol for equal to equal to in the sense a is equal to 5 is already assigned”
Logical Operators: Used to combine or negate Boolean expressions (and, or, not). Always result in a Boolean value.
“the next operator is a uh logical operator this concept will be clear okay so a equal to equal to B A is less than greater than when you just run it you will get the either true or false answer why it’s a is H so A and B is not the same that’s why it’s giving the answer is false a is greater than b so the answer is giving the true a is not greater than b okay maybe I didn’t run the this command that’s why yeah it’s taking the previous A and B values you can see here a is not equal to equal to B I wrote it that getting the answer is false where a is greater than b so a is five and B is a 7 that giving the answer is false because five is not greater than 7 okay if is not equal to you can also write the concept like if uh uh a equal to equal to 5 actually the a is a five I assign the values and I’m also writing the five when you just run it you’ll getting the answer is true okay the next operator which I discuss in this uh uh operator as well let me just remove it the next operator is uh yeah okay so next operator is logical operator as I said that this is always giving TheLogical format we can say the value is a bullion true and false is a bullion okay logical operator is and or not”
Identity Operators: Used to check if two variables refer to the same object in memory (is, is not). Work similarly to == and != for values within the range of -5 to 255 due to Python’s object interning.
“identity operator is very similar to the equal to and uh uh is not is very similar to not equal to so it identify the values like a is equal to 5 and B is equal to 7 and C is equal to a five again so a is C so it very similar to the equal to equal to it also giving the bullan answer okay G given the bullan answer which is a true and false bullan is nothing but a true and false values that we are calling bullan values”
Membership Operators: Used to check if a value is present in a sequence (in, not in).
“membership operator membership operator is in not in okay the value is a particular member variable or not suppose I have one variable which have a list is a 5 7 8 9 so five in a or not like this practically you can easily understand”
Bitwise Operators: Mentioned as less frequently required for general programming but important in specific fields. Symbols like &, |, ^, ~, <<, >>.
“one operator is also there is a bewise opor which is not much required for um for pro as a programming perspective if you belong to the any edic field so that time is really important but still I’ll give you the resource where the bewise operator is also available so you just run it you will also understand the beat wise as well but this main operator list try to understand it in a theoretically and practically both the way”
6. String Data Type:
Immutable and Ordered: Strings in Python are immutable (cannot be changed after creation) and ordered sequences of characters, allowing access to individual characters using indexing (positive and negative).
“so let’s discuss about the next topic which is a string so string is one of the very important data type in Python programming language so first thing is that it’s a immutable data type immutable in the sense once you define you cannot change it and second thing is that it’s a ordered data type ordered in the sense it have a index position starting with zero and goes till the length of the string minus one and we also have a negative indexing as well starting from minus one till the beginning of the string”
Slicing: Substrings can be extracted using slicing with the syntax [start:stop:step].
“we discuss about this slicing I disclose the concatenation and we have also one more thing is a repetition okay we can also repeat it with star symbol slicing we are using the square bracket”
Concatenation: Strings can be joined together using the + operator.
“concatenation we are using this uh Plus operation is used for concatenation plus operation is used for concatenation”
Repetition: Strings can be repeated multiple times using the * operator.
“reputation we can use the star so for example I have the value is uh variable is a I want to multiply with a five then you’ll getting India India India five times so that is a reputation”
Methods and Functions: Strings have numerous built-in methods (accessed using dot notation, e.g., string.upper(), string.lower(), string.capitalize(), string.count(), string.index(), string.title()) and functions (e.g., len(), type()) for various operations.
“let’s go to discuss about uh method and function in a string uh string data type so let me just conclude what I discussed okay so I discussed this slicing I disclose the concatenation and we have also one more thing is a repetition okay we can also repeat it with star symbol slicing we are using the square bracket concatenation we are using this uh Plus and reputation we can use the star so for example I have the value is uh variable is a I want to multiply with a five then you’ll getting India India India five times so that is a reputation okay a small small thing is there to go in a very details way again you can go to the data type if you already aware about these things so you can skip or you can just make this video is a 2X or 1.x faster and just complete it and go through this uh Jupiter notebook and run this file you’ll get a better idea but don’t forget to run this uh uh jupter notebook file okay so here I already explained okay so you can just run it just shift enter shift enter run it you’ll and you’ll understand each and everything but again in case if you make any doubts if you not understand anything you can just put your question on a comment definitely I’ll reply you okay so let’s discuss about uh okay I need a space all right I need a space keep because I don’t want to remove it okay so let’s discuss about the next thing is a function and method which is very very important every data type have a different different method and function okay let me first write a method and some function so actually the method and function both are a same there is no any difference this have a very small differences there if function is always defining like a def here I’m not explaining you the details of the function whatever in build function whatever in build method is available in a string that I will discuss it here okay so why the both are a difference see method is always calling with a DOT like I have suppose a is a variable a is a variable which is the India okay so method is always using like a Dot Upper a do lower a do capitalize okay a DOT count a do index small I there is no Capital index so other uh method is also available but when you’re talking about um function so function is like a len and we are passing the values a len means length we have um uh mean we have a mix okay so these are and we have a type so actually this uh uh function is a very common for for all the data type so when you just enter in the list tole dictionary so you’ll also find it out the same type of function that will not change but the method will always change the difference between the uh function and method is that if function is always defining like this and then function name f n if I’m writing defining like this if the function is separately available we are calling function simple but if the function is available inside a class we are calling the method class class name is a okay if it’s available inside a class we are calling method so when I start the objectoriented programming I’ll go in a very details way just now you can just understand like this the method is always using with a DOT and a function we directly call it and to know that which one is a function you can directly understand like if you find it out any statement after this bracket that is a function that can be either function or method if you’re using dot method not using function okay so few method I will discuss it here and uh after that I’ll stop okay because uh no need to explain each and every method when you just run this uter notebook you can easily understand okay so as I uh Define all two variables a which is India B which is a country and I want to make it a Dot Upper so that will make it is a upper case okay it will be make as a upper case a do lower that will make it a lower case small I and uh currently the a variable is already the capitalized capitalize in the sense first letter is a capital the second letter uh remaining letter is a small one let me make one variable is equal to I’m using Python programming language okay so let me just use small I when you just use a c do capitalize okay sometimes uh when you just forget your uh you know that method spell when you make it spellings little bit wrong so it will giving you the error so the best practice is that after this variable put a dot put a tab you’ll getting a different different suggestions I’ll make a capitalize I don’t need to write everything capitalize is already there okay when I just run it you’ll get the values I’m using Python programming language so the first L make it as a capital the rest of the later will make as a small one so C do title there is one more valuable uh”
String Formatting: Methods like f-strings (formatted string literals) can be used to embed expressions within string literals for formatted output.
“so string formatting is also very important which we already discuss in the input output so this F string is nothing but a string formatting”
Escape Sequences: Special character sequences (e.g., \n for newline, \t for tab, \\ for backslash) are used to represent characters that are difficult to type directly.
“skip sequence in the sense suppose if you are uh writing some statement and the value will not be print in the place of that uh uh that symbol it will be showing the meaningful result let’s say for example I’m writing here I um working in Python programming language okay which is uh dynamically type language okay I just want some statement after the uh High I want to print in next line I’ll use the slash n so sln is basically going to the next line right it’s not like that it will be print the slash okay and after the statement again I want to in this next line it will be in the next line I want to uh dynamically typed language have some uh space as well SLB B for backspace okay B for back I’ll make the t t for a tab okay so when you just run it you’ll get the values is because of the sln is giving the next line because of this sln is giving the again next line because of this SLT is giving the again some spaces here so that’s why it’s giving the uh uh that meaningful result not exactly is the printing the values right so this one we are calling the skep sequence so I just uh Define it here a different different type of skip sequence like slash n for next line/ t for tab SLB for back space SLR for reserved and uh Slash a for alert so different different skip sequences there sorry it’s a skip sequence okay skip sequence”
Raw Strings: Raw strings (prefixed with r) treat all characters literally, without interpreting escape sequences. Useful for file paths and regular expressions.
“what is a raw string so raw string in the sense sorry draw string in the sense if if uh you want all the statements as it is I don’t want to print the meaningful result I want as it is values so just before you have to write r that will consider everything as a raw string so the value is not displaying it here sometimes it’s very useful whenever you’re reading some particular files from local machine or in particular server okay suppose if you are reading and uh somewhere the double slash is available single slash is available so python is giving some meaningful result but you don’t want you want as it is uh path so that time we are using the r especially for uh reading the CSV file in the data science we mostly using the r to avoiding the errors”
7. Tuple Data Type:
Immutable and Ordered: Tuples are immutable and ordered sequences, similar to strings but can contain items of different data types. Defined using round brackets ().
“so let’s discuss about the next topic which is a tle so tle is one of the smallest data type like uh uh like a number number is very small that was only uh you know uh the integer float and complex but the tle have some values but it’s not as much of uh big topic so let me just cover it in this video only okay so again the tle so first we have to clear that what is the definition the Supple is again it’s a immutable and ordered data type ordered data type okay when you’re talking about the how the tle is defining the tle is defining in a round bracket suppose I have a value is a five a 8 7.0 and high okay so that I store in the variable T so uh uh first of all this tle is a comes under the sequence sequence means is a particularly order and that collecting the data right so the five is a integer 7.0 is a float high is a string so that is a that’s why the tole is become a uh sequence which store the different different data type even inside a tle you can also store the list as well dictionary as well anything so the tle list dictionary in the set that working as a container so the container is nothing but a sequence okay so here as I said it’s the ordered data type so again have a positive and negative indexing is there okay sorry uh oh why it’s showing like this okay have a positive and negative indexing so 0 1 2 3 have a positive indexing and as well as we have a negative indexing as well -1 – 2 – 3 – 4 so like the tle we can also apply the uh slicing order like uh the T slice with uh uh two you’ll get some values obviously you’ll get the value is 7.0 right you’ll get the value is 7.0 in in case if you pass the T of three you’ll get the high but in case if you pass the minus 3 then the value will change that will be 8 right so we can also apply the concatenation here we can also apply the multiplication here so this symbol is used for concatenation and this symbol is used for repetion okay so and uh the likewise the uh string we have also the method and function are available so the best part of this uh tle is that not a best part but uh yeah uh the tle have a very less method when you’re talking about a method have very less and a function okay so method have very less just we have a count count method like T do count and T do index that’s it we don’t have other method is here so again is a tle uh again is a immutable so that means we can’t change the values in between and uh the function when you’re talking about so it will be the same as the which we discussed in the string that like U uh what is the max values what is the mean values what is the um a type okay there is also one more function is available which is a tle which will be responsible to convert any data type into tle okay okay so mean Max is there yeah and we have a len which is very very important Len which will show you how much uh data is available inside a tuple so let me just clear it in the practical way it’s very uh small data type we can see so again you have to refer the data type Jupiter notebook you’ll find it out the practice uh um notes there okay so tole I can Define it here in the round bracket I’ll make this the T1 be Define in the round bracket 47 7.9 and um uh high is here we can Define it and he we can Define it okay so let me also Define one more variable is a T2 where I can Define it 4 5 6 2 there is”
Indexing and Slicing: Supports positive and negative indexing to access elements and slicing to extract subsequences.
Operations: Supports concatenation (+) and repetition (*) similar to strings.
Methods and Functions: Has limited built-in methods (count(), index()) but works with common functions like len(), min(), max(), type(), and the tuple() constructor for type conversion.
Immutability: Key characteristic, meaning elements within a tuple cannot be changed after the tuple is created. This provides data integrity.
8. List Data Type:
Mutable and Ordered: Lists are mutable (elements can be changed) and ordered sequences of items, defined using square brackets []. Can contain elements of different data types.
“now let’s discuss about the next topic is a list that is the fourth data type list so list basically a a mutable data type so whatever we discussed the previous one is a tle string and numeric that was a immutable data type but this one is a mutable data type mutable and ordered data type again so mutable means changeable ordered means have a positive and negative indexing so list is always defining with this is LS is a variable defining with a square bracket that can be the any data type you can just write it like integer 5.8 is a float High okay and uh 7 five so you can Define like this so it’s a square bracket all right so have a positive and negative indexing as well because of it order so we have a 0 1 2 sorry three and four I have a NE negative indexing as well minus1 -2 – 3 -4 – 5”
Indexing and Slicing: Supports indexing and slicing like strings and tuples.
Operations: Supports concatenation (+) and repetition (*).
Methods and Functions: Has a rich set of built-in methods due to its mutability, including append(), insert(), remove(), pop(), clear(), count(), index(), sort(), reverse(), and functions like len(), min(), max(), type(), list() (for type conversion).
“so same as the tle we have also this method and function are available but because of this mutability because of the changeability we can change the values so we have so many method and functions are available so here I will discuss a few method and function and later you can just run the Jupiter notebook file you’ll understand easily so method and function our function is the same that will be Len that will be mean that will be Max that will be uh list list also the function okay and uh that will be the type okay this function very common we we we are using in uh every data type so only this one like for a list we have a list function for tle we have a tle function string we have a s Str function okay so method when you’re talking about so method is um uh we have uh like U we have a DOT count okay we have a um we have a index that that is a common it’s there for a tle and uh in string as well and we have also the other method is like append which is very famous append insert okay so many method are available so again when you just run the jupyter notebook you’ll find it out all the methods there so few method I will discuss here and I’ll discuss in some practical implementation here okay you’ll find it out in the Jupiter notebook each and everything okay as I implemented almost every method here but still if you’ll get any confusion I’m there so let me create one uh heading is a list okay so LS is a variable I’m making some values here 6 comma 3 comma 8 comma 4.7 comma uh H comma K okay so if I want to change the value is H to hello so what is the position of H which is the 0 uh 0 1 2 3 4 that is the fourth position so fourth I want to which is nothing but a h i want to make as a hello hello and later when I just check the values is LS so yes I can see the value is hello so it’s very simple we can just do it right we can just up change the values because of it’s a mutable data type we can easily change the values which is defined inside that right so here H is changed so whatever index is defining for H so in the place of H is showing the hello but you can’t do it in a tle okay”
Mutability: Allows modification of elements after the list is created. Elements can be added, removed, or their values changed.
Nested Lists: Lists can contain other lists, creating multi-dimensional data structures.
“like I want to create one list inside a list that is also possible list inside a list so that is called as a nested list”
List Comprehension: A concise way to create lists based on existing iterables.
“one more important topic is a list comprehension list comprehension is nothing but a very short way to define a list based on some conditions”
9. Dictionary Data Type:
Mutable and Unordered: Dictionaries are mutable collections of key-value pairs, enclosed in curly braces {}. They are unordered, meaning the order of items is not guaranteed.
“now we reach till fifth data type which is a dictionary so dictionary is a little bit different with tle and list what is the different different is that there is no any positive and negative indexing is there in the dictionary that means dictionary is unordered data type but it’s a mutable data type if it’s a mutable let me just write it first it’s a mutable and ordered data type sorry unordered data type unordered data type okay so there is no any positive indexing for a dictionary no any positive and negative indexing so dictionary is a defining like key value pair with curly brasses key colon values okay Curly brasses close”
Key-Value Pairs: Each item in a dictionary consists of a unique key and a corresponding value. Keys must be immutable data types (e.g., strings, numbers, tuples).
Accessing Values: Values are accessed using their keys within square brackets (e.g., dictionary[‘key’]).
“if I want to access the value is a 15 so I will write D of a okay we’ll write a d of a then you’ll get the value is a 15 if I accessing the value is a d of Z so you can get the value is 19 this way we are accessing the values”
Operations: Does not support direct concatenation or multiplication like sequences.
Methods and Functions: Offers various methods like keys(), values(), items(), get(), pop(), popitem(), update(), clear(), and functions like len(), type(), dict() (constructor).
“when I just perform some operation methods here like a D1 do Keys you’ll get the all the keys here okay so r k T5 these are keys and what is the values E1 dot uh values you will get the values here again if you uh if you already aware about that you just the run this file which is I shared with you the dictionary run this file and run this video in a 2X or 1.5x you don’t require to listen each and everything right these are very basic basic things is there and just when you run you’ll understand so I’ll just give you the complete overview here okay so suppose if I want to add some values so there is no any upend option is there right there is no any upend I want to add some values how can I add it so the D1 pass any keys I’ll passing the keys here like uh U I’m assigning the values here 1,000 so when I just run it and get the values here D1 you’ll get the U in the last values okay so like way we can also assign the values so dictionary have some um you know applications so I’ll discuss about that again I will not each I will not write each and every line code so I’m taking the help from here suppose if I’m defining the values here okay here this is the list okay so question is why I’m creating a list here why not sorry this is the tle uh why I’m creating the tle here why not a list the reason behind that tle is very much”
Applications: Useful for representing structured data with labels (keys). Can be used to simulate tables when combined with lists.
“when you just enter in the data science so everything you are dealing with a table and the table we are reading in the data frame format then you’ll start the operations so if you start the operation if you already aware about that yes this table is nothing but a collection of the keys and values right”
Dictionary Comprehension: A concise way to create dictionaries.
“likewise the list comprehension we have a dictionary comprehension as well so dictionary comprehension is also the same syntax for variable in sequence you can also put the condition as well but the only changes is that you have to define the key and values that’s it”
10. Set Data Type:
Mutable and Unordered: Sets are mutable, unordered collections of unique elements, enclosed in curly braces {} or created using the set() constructor. Duplicate elements are automatically removed.
“now the last data type is a set so set is again a mutable data type but it’s a unordered data type and it always store the unique elements unique in the sense duplicate values is not acceptable and it’s defining with a curly bras but the only difference with dictionary is that dictionary is a key value pair but here directly you are passing the values”
Uniqueness: Sets only store unique elements. If duplicates are added, they are ignored.
Unordered: Elements in a set have no specific order, and indexing is not supported.
Operations: Supports various set operations like union (|), intersection (&), difference (-), symmetric difference (^), and methods like add(), remove(), discard(), pop(), clear().
“so sets support so many operation like Union intersection difference symmetric difference and all the Venn diagram concept you can apply it here so Union means combining the two set but again it will store only the unique element intersection means common values difference means the values is there in a but not in b or values is there in b but not in a symmetric difference means except the common values rest of the values will be displayed”
Methods and Functions: Includes methods for adding (add()), removing (remove(), discard(), pop()), and updating sets, as well as set operations. Functions like len(), min(), max(), type(), set() are also applicable.
Set Comprehension: A concise way to create sets.
“there is one more application one application is there in a set which is the uh set comprehension likewise the dictionary comprehension we had we had a uh list comprehension so set comprehension is also there comprehension okay set comprehension so set comprehension the syntax will be the same like the and list so whatever for we have to use for that particular variable in sequence sequence can be any range any uh other sequence like a list or tle or or list or tle mainly so here just you have to write variable and curly bres is mandatory for a set”
11. Data Type Summary (Mutable/Immutable, Ordered/Unordered, Container/Sequence):
Container (holds multiple items): String, Tuple, List, Dictionary, Set
Sequence (ordered container with indexing): String, Tuple, List
12. Conditional Statements (if, elif, else):
Flow Control: Used to execute different blocks of code based on whether certain conditions are true or false.
if Statement: The starting point of a conditional block. The code within the if block is executed only if the condition is true.
“the condition is always start with if we are writing if take a space and write it down a is greater than b okay that uh your condition after the colon it automatically taking the four space that we are calling indentation and we consider as a block if I write the statement as a print hello and when you just run it and it will be check the condition is satisfied or not”
elif Statement: Used for additional conditions to check if the preceding if or elif conditions were false. Multiple elif blocks can be used.
“but I want to write one more condition so obviously I have to go back and write one more condition which is the L if L if C is greater than b colon let’s write some statement statement is hey and if I want to one more uh uh if I want one more condition I’ll write it the L if is a is greater than C there is a three condition I mentioned there and simultaneously you can just write a many condition is here okay hello hey hi”
else Statement: An optional block that is executed if none of the preceding if or elif conditions were true.
“and after that we always using the ls this is the good practice in case if you’re not using it will not show you any error so likewise here it’s not showing any error so same wise here it will not show any error if you’re not using else just write down here else colon and your statement print hello uh just buy else is always execute if any block is not executed previously if any block is not executed that time is working”
Top-to-Bottom Evaluation: Python evaluates the conditions in order from the if statement downwards. Once a condition is true, the corresponding block is executed, and the rest of the conditional block is skipped.
“python is always working the top to bottom okay it always check that line number one is um um satisfied or not satisfied a is greater than b the meaning is that a is greater than b B that is false Okay C is greater than b which is true a is greater than C which is also false and else is always is a default one in case previous one is not executed that time it will run okay so here the block number two here the third one line number three is execute it when you run it it giving the answer is he but what happened is all the condition is satisfied all the condition is true like a is greater than b okay A a is less than b uh and C is greater than b and uh a is also less than C that all the condition is satisfied so what will be the answer the answer will be the first one because according to the rules here which we discussed if the first condition is satisfied is giving the statement and terminate the Block it’s not entering the next block because l l if will check if the first condition is dissatisfied right if the first condition is satisfied is giving the statement and terminate the block but here the L if is after the false of the first condition so here it giving the answer is hello one day again the last one if no any condition is satisfied that time the buy will execute which is the default one if nothing is there nothing no any condition is satisfied like uh I’ll just change it here uh greater than less than greater than so all the condition is false there is no any true condition and uh so when you just run it it giving the answer is by because nothing is satisfied here this is the way of conditional statement we are using”
13. Loop Statements (for, while):
Iteration: Loops are used to repeatedly execute a block of code.
for Loop: Iterates over a sequence (e.g., string, list, tuple, range).
“basically the for Loop is used for the iterating of the process if anything is available in a uh you know in any container if you want to iterate it if you want to display the one by one we are using the for”
range() Function: Generates a sequence of numbers, often used with for loops. range(start, stop, step). The stop value is exclusive.
“sequence is uh scq limes right scq is equal to range so range is one of the function which provided the sequence from one number to another number with interval so if I’m passing the range is like 1 till 15 yeah 11 so python have a rules that it never end with last values it end always before one so if I’m I’m writing the 1 to 11 that means it’s a 1 2 3 4 5 6 7 8 9 it never goes till 11”
Iterating Through Sequences: for loops can directly iterate over elements of lists, tuples, strings, etc.
“the same thing is applicable for any list as well so in the list I have a multiple values for V in list print V so it will print the one by one”
Nested Loops: Loops can be nested within other loops to iterate over multi-dimensional data structures.
“if you have a list inside a list inside a list that is a 3D so you have to apply the three for Loop to read each and every element”
while Loop: Executes a block of code as long as a specified condition is true. Requires careful management of the loop condition to avoid infinite loops.
“while loop is also for the iterative purpose but it will be continue the process until the condition become false so we have to initialize one variable and provide the condition here and inside a block we have to either increment or decrement that variable so that particular condition will be false otherwise it will be run infinite time so we have to take care about the while loop”
break Statement: Used to immediately exit a loop.
“if any condition is satisfied in between I want to just stop the loop I can use the break statement”
continue Statement: Skips the rest of the current iteration of a loop and proceeds to the next iteration.
“if any condition is satisfied I just want to skip it I don’t want to stop the loop I just want to skip and continue the next iteration I can use the continue statement”
else Clause in Loops: Can be used with for and while loops. The else block is executed if the loop completes normally (without being terminated by a break statement).
“there is one more interesting thing is that the else block is also available with the for Loop and while loop but it will be execute only if the loop is completely executed if the loop is break in between the else block will not be executed”
Real-life Example (Login Attempt): The source provides an example of using a while loop for login attempts with a counter and the possibility of pausing the process using the time.sleep() function after a certain number of failed attempts.
“I’ll just use the while count is greater than zero I’ll ask the username input enter your username and password input enter your password okay and uh if my condition is username is equal to equal to hurry and password is equal to equal to hurry 1 2 3 my login will be successful print login successful and I’ll break it I don’t want to continue the process anymore but in case if my username and password is wrong is more than three times then the process should stop for particular duration I’ll just make it minus okay then it will showing that uh it only three times is remaining only two times is remaining this kind of you’ll get only three attempts okay the same statement I’ll apply for if the username is wrong my username is wrong and I’ll make it comma uh this particular attempt is remaining all right so okay this okay so if my usern is wrong uh all right I forgot to write F this is string formatting if my usern is wrong two attempt is remaining one attempt is remaining zero attempt is remaining in the sense is the last one it should be stop it here so I have to put one more condition if the count become a zero I have to stop it what I can do it here uh so anywhere like uh the breaking the loop if my loging successful I can also write L if Al if we can write Al if the count is equal to equal to zero the time please wait for 10 second currently I’ll just write in the 10 second okay 10 second and after that process should start again all right so I’ll do the same process for uh this is for password I’ll do the same thing for username as well I do it username as well but the your process should stop for 10 second so how can we do that so there is a like library is called as a Time import time okay so you can directly write the time do slip your process will stop for particular duration so I’ll do it here time do slip for 10 second so automatically it’s a second how can we know that you can just write time. slip and bracket you can just check it what exactly is there it’s a second I click on here inside and click shift tab this option is available in the Jupiter notebook only and if you have any other ideally you can find it out other options okay let me just remove so the process will stop for 10 second and after that it will again start so it’s on you if you want to put the timing you can okay so currently it will be stopped for 10 second process will yeah only two attempts is remaining one attempt is remaining I’ll write hurry password I’ll make it wrong this is the last attempt zero attempt is remaining that means there is no any attempt this is the last one I’ll write it here uh hurry password is hurry wrong let me just write it just wait for 10 second the process is still running it’s not like that your process is totally end up it’s running for 10 second it hold for 10 second you can increase it now it’s ask asking the password again hurry I will write it and again it’s waiting for 10 second because it’s already been uh uh already been you know um is a kind of uh uh already your count was Zero that that’s why it’s waiting for 10 second but it should not be it should not be after 10 second it give the three times option right but here I’m passing the wrong password still is waiting for 10 second so that one glitch is there there I have to just change it uh it should be make it zero again uh it should make it uh three again all right so I use it hurry 1 2 3 and let’s make it yes”
14. Functions:
Code Reusability: Functions are blocks of organized, reusable code that perform a specific task. They help in modularizing code and making it more readable and maintainable.
“function is nothing but a block of code which perform a specific task and it is reusable”
Types of Functions:Predefined (Built-in) Functions: Functions that are already available in Python (e.g., print(), len(), type(), int(), range()).
“predefined which is system is already given the function we are just using it right mean Max int print whatever you you already use it that is a predefined function you just just call and pass the values you’ll get the answer”
User-Defined Functions: Functions created by the programmer using the def keyword.
“we can also make the function which is we are calling user defined function that means we are defining the function the third one is anonymous function we’ll discuss in um practical manner a function without name so here you can see the uh you can see the def and function name”
Anonymous (Lambda) Functions: Small, unnamed functions defined using the lambda keyword. Often used for simple operations where a full function definition is unnecessary.
“the third one is anonymous function which is also called as a Lambda function we can define the function without name with Lambda keyword with Lambda keyword”
Recursion Functions: Functions that call themselves during their execution. Requires a base case to prevent infinite recursion.
“the last one is a recursion function that things we’ll also discuss”
Defining Functions: Use the def keyword followed by the function name, parentheses for parameters (optional), and a colon. The function body is indented.
“let’s make a block is a depth EF and function name is a equation equation okay as I told you bracket is very very important parameter it’s on you if you want to Define you can otherwise you can leave it and uh like equation is the equation is y equal x squ plus 2X you required X as a input so I’ll just pass it here parameters now your block is ready I’ll just print it y okay I’ll just print it Y and I just run it you’ll not get any answer function have a rules without calling the function function will never execute okay so here I can see this is defining the function defining the function”
Calling Functions: Functions are called by using their name followed by parentheses, passing arguments if required.
“I want to call it so what I’ll do I have to define the values X is equal to some some something or else you can directly uh pass the values equation I’ll pass the value is five so you’ll get the answer accordingly so this one we are calling the function this section calling the function okay this SE is calling the function”
Parameters and Arguments: Functions can accept input values through parameters defined in the function signature. When calling a function, the actual values passed are called arguments.
Return Statement: The return statement is used to send a value back from the function to the caller. After a return statement is executed, the function terminates.
“the dev hello there is a function and if my number number is a = to 4 and B is = 8 and return is equal to a + and before return let me just use the print print A+ B and when you just call it hello you’ll get the answer is 12 and after the print statement uh my statement is there um um hello world okay this normal statement hello world after 12 is showing that hello world but in case if you use the written statement for a plus b return statement for a plus b hello world where hello world will never display the reason behind that because after the print after the written statement whatever things is there will never be execute”
Lambda Function Syntax: lambda arguments: expression.
“we are writing the Lambda Lambda and we’re passing the arguments like uh a sorry a comma B and then you uh doing some operations let’s understand it here so syntax is not much important but you should know that how we are writing so just we have to write Lambda what operation you want to perform I want to perform the operation of um a cube of any numbers yeah we can say U addition of XY Z so I have to Define it X comma y comma Z colon colon what operation you want to perform I want to perform is the 2 into x + y + z that equation I want to perform when you just run it we’ll find it out the function is created”
Use Cases for Lambda Functions: Often used with functions like filter() and map() for concise, inline operations.
“Lambda keyboard is using if your function is very small and you are it iteratively calling it the time we are using you don’t need to Define it separately you in that function itself in that predefined function itself you can use the Lambda”
Recursion Function Example (Factorial): The source demonstrates a recursion function to calculate the factorial of a number, where the function calls itself with a decremented value until a base case is reached.
“suppose I have a number is n and uh here I pass the value is a five and every time when you call this process when you call this function I’ll make it n minus one at the same time I can also print that n as well so that I can track it how much value is there so when I just run it you can see here the 5 4 3 2 1 and and it’s going till down there is there is a limit is a 3,000 so it will be going down and run it again and again right so what I can do hit here so when you scroll down down down down it’s a 7,000 it’s going to more than 7,000 the reason behind that I increase the limit which is the 8,000 right I increase the limit that’s why it’s going till here after uh 7,000 7,000 something and is going this statement is maximum recursion depth exced while calling the python object my target is that I want to stop in after five steps so I can use it here the condition if my n become a zero that time I will return return just um uh recursion done okay the statement is is a recursion done that’s it so because you know that after the return statement any statement is written there it will never accept okay so when I just run it it will going till uh 1 only what exact what is the meaning is that it’s not acceptable after the return statement like I think I already discussed but again I’ll tell you in the short way the dev hello there is a function and if my number number is a = to 4 and B is = 8 and return is equal to a + and before return let me just use the print print A+ B and when you just call it hello you’ll get the answer is 12 and after the print statement uh my statement is there um um hello world okay this normal statement hello world after 12 is showing that hello world but in case if you use the written statement for a plus b return statement for a plus b hello world where hello world will never display the reason behind that because after the print after the written statement whatever things is there will never be execute”
15. Modules and Packages:
Modules: A Python file with a .py extension. Contains Python code (functions, classes, variables). Used for organizing code and reusability.
“module is nothing but uh any python file which have a py extension is called as a module so you have so many python file you create but sometime we creating the Jupiter notebook file that Jupiter notebook extension is i p y and B so that is not a module so python file should be in the py extension that will consider as a module and the module can consist of function classes variable anything because that is the file inside a file so many things we can write it”
Packages: A directory containing multiple modules and a special file named __init__.py. Used for structuring larger Python projects and preventing naming conflicts between modules. Sub-packages are packages nested within other packages.
“package is nothing but one uh directory we can say where consist of the multiple modules but there is one special file is called as init so that name is init it should be available there that we are calling packages so for example I have a file which is the uh a which is the file name is a. py B do py c. py so these are all a modules but make sure that there is one more file should be underscore uncore init uncore uncore py if this one is also present and it’s available in the particular folder uh suppose the folder name is okay yeah suppose the folder name is main so main is nothing but a package which consist of the multiple modules”
Libraries: Often used as a general term for a collection of related modules and packages that provide a set of functionalities.
“someone is also calling this one is a library someone is also calling this one is a library so library is nothing but is a collection of the packages”
Importing Modules: Use the import keyword to bring modules into your current script. Specific names can be imported using from module import name.
“so I want to call it this function with different file so calling is a file both load and calling is available in the same location I want to call the load module so how to call any module we are using the import keyword import load”
Finding Module Location: The sys module and sys.path list can be used to determine the directories where Python looks for modules.
“there is one um library is in build Library which is a CIS CIS is a system so let me just open the python here directly sorry here anywhere you can open it I can write it here okay so import CIS system sis. paath so it will showing you the path where exactly all the libraries and all the python packages are available”
Installing Packages with Pip: pip is the package installer for Python. Used to install and manage third-party libraries from the Python Package Index (PyPI). Command: pip install package_name.
“p is working as a package manager which is responsible to install any kinds of packages or libraries so if you’re using the python more than uh 3.4 version so that means PP is already there you have to just use it so if you want to install a package like pandas so you can write it you can write it like pip install pandas that’s it”
__name__ Attribute: A built-in variable that holds the name of the current module. When a script is run directly, __name__ is set to “__main__”. If a module is imported into another script, its __name__ is set to the module’s name. This is often used to include test code or main execution logic within a module that should only run when the module is executed directly.
“there is one more topic is a name attribute I think you saw this name attribute in a Python programming language is many places so let’s understand it how we can use this name attribute so suppose if you have vs code okay if you have a vs code and uh yeah and I have one file which is a um load file load. py so the variable is 55 and DEP is equal to info and uh pass the statement is this is this is uh load module okay and one more function is available def add and pass to parameter a comma B simple and just um you know perform some operation result is equal to a + b and later return the values return the result okay now it’s done but I want if if I if my target is to create the complete a module which will be the load module but I want to test it that whatever function I wrote it that is perfectly fine or not okay so here uh I just want to um you know test it this add function is properly running or not so what I’ll do I’ll just call the function 5 comma 8 and when I run it so hopefully we will not get any answer because I return the values but when I just print the statement like uh print the statement directly so we will get the answer is 1 so which um I was expecting 13 now the answer is also 13 everything is perfect but here I just want to call the load module let me just call it import load okay and when you just import load let’s see what will happen so import load I just load the I just uh you know load the load module that name is the same I just imported the load module but here I was not expecting that answer should be the 13 because I didn’t call the add function here I didn’t call the add function let me just call the add function uh print load do add I’ll pass the values is 5 comma 12 so I’m expecting the answer is 17 so here I got the 17 but the same time I also got the answer is 13 as well which is wrong not wrong but uh I have to see that where exactly this 13 so 13 is basically I just printed here in the load module just”
16. Exception Handling (try, except):
Handling Errors: Exception handling is a mechanism to gracefully manage runtime errors (exceptions) that can occur during program execution, preventing the program from crashing.
“exception handling is basically used for to handle the unexpected event during the program execution”
try Block: The code that might raise an exception is placed within the try block.
“I’ll just use a try try means I’ll just normally try the normal flow of the program so normal flow of the program I’ll right okay so in case any exception occurred except”
except Block: If an exception occurs within the try block, the code within the corresponding except block is executed. You can specify the type of exception to catch.
“except exception accept exception uh the time I can I can write it here print Infinity okay I can I can write it anything so if I pass 6 IDE 0 you’ll get the answer is infinity whatever you write it here you’ll get the answer accordingly”
Real-life Analogy: Likens exception handling to a car’s fuel indicator: it doesn’t solve the problem of an empty fuel tank but alerts the driver to take appropriate action.
“if the petrol is finished the fuel indicator is giving the answer you’re giving the uh instruction that yes your petrol is finished find it out some nearby petrol pump so the fuel indicator is not solving the problem but is giving the instruction that this is the exact instruction you can handle via petrol so this is one of the example”
17. File Handling:
Opening Files: The open() function is used to open files for reading or writing. It takes the file path and the mode (‘r’ for read, ‘w’ for write, ‘a’ for append, ‘r+’ for read and write, etc.) as arguments.
“file handling is basically we have to perform the operation with the file like a reading the file writing the file updating the file and deleting the file so these are the four basic fundamental operation we can perform it and to perform this operation we have a inbuild function is called as open function”
File Modes: Different modes determine the operations that can be performed on the file. ‘w’ overwrites existing files or creates a new one, ‘a’ adds to the end of an existing file.
“your mode should be w w means writing the files and then line by line I’m just writing the file this is my first program this is my second program I’m writing there so make sure that you have to close it otherwise it will be impact to the another files if you opening in a new section so yes I close it that means file is properly written sometimes we are not closing the files so what happened ke if you write the program uh if you apply the uh writing some uh you know lines in a text but you forget to close it so that time the file exactly not writing in the text file okay so now file is a properly written”
Closing Files: It’s important to close files using the close() method to release system resources and ensure data is written to the file.
“make sure that you have to close it otherwise it will be impact to the another files”
with open() Statement: Provides a convenient way to work with files. It automatically closes the file even if errors occur. Recommended practice.
“one more option is also available which is a with open we have to use a with open it and if you using the withth open you don’t need to close it the reason because you’re writing entire section inside the block if you’re coming out the block that means file is already closed so this is also one of the good practice”
Reading Files: Methods like read() (reads the entire file), readline() (reads one line at a time), and iterating over the file object (reads line by line) are used to read file content.
“so if I want to use the reading okay so make sure that I should have some files okay uh so python. txt I create I have one files is a big file so you can also find it out files on um GitHub okay before going to the python. txt let’s also read something okay you can also read the my my text.txt as well let me show you how we can read it so with Way open you can also use it with open I’m just opening the file which name is my txt do my text.txt my my text.txt and mode is equal to it’s r r for reading okay and then uh uh we have to define the Define the you know as a variable as F3 I’m just defining it okay F uh F50 I’m just defining maybe it will be impact the next one because 3 four I just use it there so I’m just use the F50 F50 dot read line and then read line that’s it so it will be uh store somewhere let me store in the where one okay so we can also check that is the first line which will be printed where one so this is my first program so whatever I write it I can also read it as well”
Writing to Files: The write() method is used to write strings to a file.
Appending to Files: The ‘a’ mode allows adding content to the end of a file without overwriting existing data.
seek() Method: Allows changing the file pointer position to a specific offset, enabling reading or writing from different locations within the file.
“here we have a a method is a seek method seek method is exactly we can just Define the positions from where you want to start it like I I I decided that I want to start some particular position which is the python is interpreted objectoriented high level programming language suppose I want to start from there so how we can start it like we our cursor is always starting from here but I want to start here so seek will Define the position in a python yeah we can say here in this location and then it will”
18. OS Module:
Operating System Interaction: The os module provides functions for interacting with the operating system, such as working with file paths, directories, environment variables, and running system commands.
“OS module is also one of the very important module which will be interact with your operating system like creating the folder deleting the folder and uh checking your current directory changing the directory so so many operation we can perform it”
Common Functions: Includes functions like os.getcwd() (get current working directory), os.chdir() (change directory), os.mkdir() (make directory), os.makedirs() (make multiple nested directories), os.rmdir() (remove directory), os.rename() (rename file or directory), os.path.join() (join path components), os.path.exists() (check if a path exists), os.cpu_count() (get the number of CPUs).
“OS module is also one of the very important module which will be interact with your operating system like creating the folder deleting the folder and uh checking your current directory changing the directory so so many operation we can perform it let me just show you a few practical examples so currently my current directory is this so if I want to check it OS module first you have to import OS and OS do get CWD so you’ll get your current working directory if you want to change your directory OS do chdir and pass the path wherever you want to go your path will change and next time when you just check it os. getet CWD so you will get it the current location which is the recurrent learning video on python tutorials and some operation we can also perform is like um I want to make some directory I want to make some uh you know some folders directory is a folder so how we can create it uh current location is this this in the sense here nothing in no any folder is available I want to create any folder how we can create it mkd sorry OS do mkd and pass the values you can you can write anything uh I’m just writing temp directory temp di so when you just run it so temp directory will generate yeah temp directory is generated so with the help of os module you can perform some operation with your computer so that python is providing that kind of facilities other programming language is also there just I’m telling you the python have the OS moduel and uh in case if you have the multiple directory for example my current location my current directory is this and I want to create the multiple directory inside a directory like path is equal to I want to create um you know new dir inside the new di I want to create one more directory is a okay analysis okay inside analysis and then um uh we can say Titanic okay this folder I want to create it but if you’re using the. M KD let’s see it will work or not so os. mkdir path let’s see it will showing throw the error the system cannot specify the path because your current directory is this and inside that you want to create the multiple directories so which is not possible with a mkdir so different method is available which is a Mech DS Mech directories so when you just using the me directories so you can create a folder inside a folder inside a folder like that so let me show you yeah new di inside that analysis inside that Titanic so this way we can create it okay so in case I don’t want any directory suppose I don’t want a temp directory still there so OS Dot .rm and provide the path which is the temp Dr so that directory will delete RM di sorry rmd so that directory will delete as well so this kind of option is also available to you can also delete it okay there is one only one directory which is the new d new dir there is no any temp di because I deleted I want to change this name I don’t want you know this new IR I want to rename it so OS dot rename it okay so rename it so what is the file name new di I want to change it as a new only okay rename n a m e rename sorry so new di I just change it is a new so change it here so that kind of option is available so let me just do the last two method and after that I’ll I’ll show you the list you can easily explore it suppose my current directory uh my current directory is this current di let me just do it o.get CWD okay this is my current Di okay I want to perform some operation uh so like uh I want to add it like new Di and with all the locations right so how we can do it like inside a DI there is analysis folder is available so we can also join the path as well so OS do os. paath do join so my current directory current Di with whatever path you want to join it suppose I want to join with a new so it will be joined like this okay so you can perform the analysis and based on that so. path. jooin you can joining with the two One Directory with any other directory in case I want to create One Directory which name is a new which is already exist let me R OS do mkd which is name is new let’s see what will happen so it will throw the error and saying that cannot create a file when that file is already exist so there is a condition we can also apply it okay if os. paath do exist and you can write it that new in case if new is exist the time in case if new a exist if os. path. exist the time will not create okay okay okay let me just try uh okay so it’s kind of if path the the different path is exist then you can create it like I want to uh this one is just tell you like the path is exist or not like I want to check that yes or no so it will show yes that path is exist so in case the new is exist inside that I want to create one uh location like here like here inside a new I want to create it inside new folder I want to create one more folder which name is uh data science okay inside a new I want to create it in a data science likewise okay let me tell you new okay temp Dr and then data science okay so like this live it let me make it the very simple I want to create new directory os. mkd which is name is new I want to create it but it’s already exist so it throw the error so what I can do if not os. path. exist new if it’s not there then it’s create otherwise don’t create so it will not throw the error in case new is not available so currently new is available it’s not enter inside the location but in case if it’s not available I delete it when you run it here so it will be create but inside nothing is there because just now it created okay so when you just apply this kind of condition if not os. path that exist then it’s created otherwise don’t create so in OS module lots of method is available so I just provided the link in a Jupiter notebook W3 schools you can also explore it like anything like I want to know that CPU count okay with a CPU count you can also use it how many CPU is there and you can also perform the operation there is a four CPU kind so likewise I want to also check that in my PC how many CPU count is there so OS do CPU count okay it’s not counts think yeah there is a 12 CPU count is there in their system is a four so likewise you can also explore it other method which is available here”
19. File Handling (Pickle, JSON, CSV):
Pickle: A module for serializing and de-serializing Python object structures (pickling and unpickling). Allows saving complex data structures to a file and loading them back. Pickle files are binary format.
“pickle is used for preserving the data so like if you save this kind of data into any format like a Json format or normally the text format you can see easily right if you double click with a notepad you can uh see that kind of files but pickle is always store”
JSON: JavaScript Object Notation, a lightweight data interchange format. Python’s json module allows encoding and decoding JSON data. Commonly used for web applications and data transfer. JSON files are human-readable text format.
“Json is also for the same purpose if you want to transfer the data from one application to another application so Json is mostly used in web application”
CSV: Comma Separated Values, a simple text format for storing tabular data. Python’s csv module provides functionality to read and write CSV files.
“CSV is also one of the very famous file format if you want to store the tabular data in a very simple way like in Excel format so CSV is very useful”
This briefing document provides a comprehensive overview of the fundamental Python concepts covered in the source. Further exploration and practical exercises, as suggested by the source’s reference to a Jupyter Notebook, are crucial for solidifying understanding.
Python Fundamentals: Variables, Data Types, and Operators
1. What is a variable in Python, and how does it relate to data types and memory allocation?
In Python, a variable is essentially a name that refers to a location in the computer’s memory where data is stored. When you assign a value to a variable (e.g., a = “hello” or b = 15), Python allocates a portion of memory to hold that data. The data type of the value (like string, integer, float) determines how this memory is allocated and interpreted. Each variable, being a memory location, also has a unique identification number, which can be retrieved using the id() function. The amount of memory allocated and the identification number can differ based on the data type of the value stored in the variable. For instance, a string might require more memory than an integer, leading to a larger gap between their identification numbers when created.
2. What are the main built-in data types in Python, and can you provide examples of each?
Python offers several built-in data types, categorized mainly as:
Numeric:Integer (int): Whole numbers without decimal points (e.g., 15, -3).
Float (float): Numbers with decimal points (e.g., 19.8, -2.5).
Complex (complex): Numbers with a real and an imaginary part (e.g., 3 + 5j).
Boolean (bool): Represents truth values, either True or False.
Set (set): Unordered collections of unique elements (e.g., my_set = {1, 2, 3}).
Sequence Types: Ordered collections of items.
String (str): Sequences of characters enclosed in quotes (e.g., “hello”).
List (list): Ordered, mutable sequences of items enclosed in square brackets (e.g., my_list = [1, “hello”, 3.14]).
Tuple (tuple): Ordered, immutable sequences of items enclosed in parentheses (e.g., my_tuple = (1, “hello”, 3.14)).
3. What are keywords in Python, and what are the rules for using them?
Keywords in Python are reserved words that have specific meanings and purposes within the language. They cannot be used as identifiers, such as variable names, function names, or class names. Python has a predefined set of keywords (e.g., if, else, for, while, def, class, True, False, None). You can see a list of Python keywords using the keyword module and keyword.kwlist. Attempting to use a keyword as an identifier will result in a syntax error.
4. What is indentation in Python, and why is it important?
Indentation in Python refers to the spaces or tabs used at the beginning of a line of code to define code blocks. Unlike many other programming languages that use curly braces {} to delimit blocks, Python relies solely on indentation. Consistent indentation is crucial because it determines the structure and execution flow of the program, especially within control flow statements like if, for, and while, as well as in function and class definitions. Incorrect indentation will lead to IndentationError and will change the logical grouping of statements. The standard convention in Python is to use 4 spaces for each level of indentation.
5. How do you take input from the user and display output in Python?
In Python, you can take input from the user using the input() function. This function prompts the user with an optional message and returns the user’s input as a string. If you need the input to be of a specific data type (like an integer or float), you need to explicitly convert it using functions like int() or float(). For example:
name = input(“Enter your name: “)
age = int(input(“Enter your age: “))
To display output in Python, you use the print() function. You can print strings, variables, and the results of expressions. You can also format the output using f-strings or the .format() method to include variables within strings. For example:
print(“Hello,”, name)
print(f”You are {age} years old.”)
result = 10 + 5
print(“The result is”, result)
6. What are operators in Python, and what are the main categories of operators?
Operators in Python are symbols that perform operations on values (operands). Python supports various types of operators, including:
Arithmetic Operators: Used for mathematical calculations (e.g., + for addition, – for subtraction, * for multiplication, / for division, ** for exponentiation, // for floor division, % for modulo).
Assignment Operators: Used to assign values to variables (e.g., =, +=, -=, *=, /=, %=).
Relational (Comparison) Operators: Used to compare values (e.g., == for equal to, != for not equal to, > for greater than, < for less than, >= for greater than or equal to, <= for less than or equal to). These operators return Boolean values (True or False).
Logical Operators: Used to combine or modify Boolean values (e.g., and, or, not).
Identity Operators: Used to check if two variables refer to the same object in memory (is, is not). Note that for small integers (-5 to 255), Python might reuse the same object ID.
Membership Operators: Used to test if a value or variable is found in a sequence (in, not in).
Bitwise Operators: Used to perform bit-level operations on integers (&, |, ^, ~, <<, >>).
7. Can you explain the concept of immutability and mutability in Python data types and provide examples?
Immutability: An immutable data type is one whose value cannot be changed after it is created. If you perform an operation that seems to modify an immutable object, you are actually creating a new object with the modified value. Examples of immutable data types in Python include:
Numbers (int, float, complex): When you add two numbers, you get a new number object.
Strings (str): String operations like concatenation or slicing create new string objects. You cannot change individual characters of a string in place.
Tuples (tuple): Once a tuple is created, you cannot add, remove, or modify its elements.
Mutability: A mutable data type is one whose value can be changed in place after it is created, without creating a new object. Examples of mutable data types in Python include:
Lists (list): You can add, remove, or modify elements of a list directly using methods like append(), insert(), remove(), or by assigning to specific indices.
Dictionaries (dict): You can add, remove, or modify key-value pairs in a dictionary after its creation.
Sets (set): You can add or remove elements from a set using methods like add() and remove().
The distinction between mutable and immutable types is important for understanding how data is handled and how variables behave in Python, especially when passing objects to functions or assigning them to multiple variables.
8. What are the key characteristics and operations associated with Python’s sequence data types (strings, lists, tuples)?
Strings (str):
Ordered: Characters in a string have a specific order, and you can access them using positive and negative indexing.
Immutable: Once a string is created, its characters cannot be changed.
Operations:Slicing: Extracting a portion of a string using index ranges (e.g., s[1:5]).
Concatenation: Combining strings using the + operator (e.g., “hello” + ” world”).
Repetition: Repeating a string using the * operator (e.g., “abc” * 3).
Methods: Numerous built-in methods for string manipulation like upper(), lower(), capitalize(), count(), find(), replace(), split(), join().
String Formatting: Using f-strings or the .format() method to embed variables in strings.
Escape Sequences: Special character combinations like \n for newline, \t for tab.
Lists (list):
Ordered: Items in a list have a specific order, accessible by index.
Mutable: You can change the elements of a list after it’s created.
Operations:Slicing: Similar to strings, but returns a new list.
Concatenation: Using the + operator to combine lists.
Repetition: Using the * operator to repeat list elements.
Methods: Many methods for modifying lists: append(), insert(), remove(), pop(), sort(), reverse(), extend(), count(), index().
List Comprehension: A concise way to create lists based on existing iterables.
Supports nested lists (lists within lists).
Tuples (tuple):
Ordered: Elements in a tuple have a specific order, accessible by index.
Immutable: Once a tuple is created, its elements cannot be changed.
Operations:Slicing: Returns a new tuple.
Concatenation: Using the + operator to combine tuples (creates a new tuple).
Repetition: Using the * operator to repeat tuple elements (creates a new tuple).
Methods: Fewer methods compared to lists: count(), index().
Tuples are often used for fixed collections of items and can be more memory-efficient than lists in some cases. They can also be used as keys in dictionaries (unlike lists).
Jupyter Notebook and Python Fundamentals Illustrated
Based on the provided source, here are some basics of Jupyter Notebook:
Installation and Launching:
Jupyter Notebook can be installed in several ways, including using Anaconda or Miniconda, or directly via the command prompt using pip.
The source recommends using Anaconda for data science as it conveniently installs Jupyter Notebook, along with other useful tools like Spyder, and comes with many pre-installed libraries such as pandas, NumPy, Matplotlib, and Plotly.
To install Anaconda, you can go to the official website and download the free version. The installation process involves a simple double-click and following the on-screen instructions.
After installing Anaconda, you can find the Anaconda Navigator in your applications (e.g., under the “Anaconda3” folder in Windows). From the Navigator, you can launch Jupyter Notebook.
Alternatively, you can directly search for “Jupyter Notebook” in your operating system’s search bar to open it.
When launched, Jupyter Notebook typically opens in your default web browser.
Interface and Usage:
Jupyter Notebook opens in a specific local directory on your computer (e.g., your C drive user directory).
The interface allows you to navigate through your files and folders and create new notebooks.
To start writing Python code, you can create a new Python 3 notebook.
Code is written and executed in cells. You can write Python code in a cell and run it by clicking the “run” button or by using the shortcut Shift+Enter.
Jupyter Notebook files have the extension .ipynb.
Key Features and Concepts Illustrated in the Source:
Basic Python Concepts: The source uses Jupyter Notebook extensively to demonstrate fundamental Python concepts such as:
Variables and how they store data according to their data types.
Data types, including numeric (integer, float, complex), string, list, tuple, dictionary, and set, with examples of how to define and check their types using the type() function.
Memory allocation for variables and how to check their identification numbers using the id() function.
Keywords and how to list them using the keyword module.
Indentation as a way to define code blocks in Python.
Comments using the hash symbol #.
Operators: Jupyter Notebook is used to practically demonstrate different types of operators:
Arithmetic operators (+, -, *, /, %, //, **).
Assignment operators (=, +=, -=, *=, /=, etc.).
Relational (Comparison) operators (>, <, >=, <=, ==, !=) which always return a Boolean value (True or False). These are also referred to as conditional operators.
Logical operators (and, or, not) which work with Boolean values.
Identity operators (is, is not) which compare object identity (memory location).
Membership operators (in, not in) which check if a value is present in a sequence.
Data Structures: The source provides examples in Jupyter Notebook to illustrate the properties and operations of various data structures:
Strings: Including slicing, concatenation using the + operator, repetition using the * operator, and various built-in methods (e.g., .upper(), .lower(), .capitalize(), .count(), .index()) and functions (e.g., len(), min(), max()). It also covers string formatting, skip sequences (e.g., \n, \t), and raw strings (using r’…’).
Tuples: Showing how to define them using round brackets, their ordered and immutable nature, positive and negative indexing, slicing, concatenation, repetition, and the available methods (.count(), .index()) and functions (len(), min(), max(), tuple(), type()).
Lists: Demonstrating their definition using square brackets, their mutable and ordered nature, indexing, slicing, concatenation, repetition, and numerous methods (e.g., .append(), .insert(), .remove(), .pop(), .sort(), .reverse(), .clear()) and functions (e.g., len(), min(), max(), list(), type()). The source also introduces list comprehension as a way to optimize code.
Dictionaries: Illustrating their definition using curly braces with key-value pairs, their mutable and unordered nature, accessing values using keys, and various methods (e.g., .keys(), .values(), .items(), .pop(), .clear(), .get(), .update()) and functions (e.g., len(), type(), dict()). The source also touches upon how dictionaries can be used to represent tabular data and introduces the pandas library in this context.
Sets: Showing their definition using curly braces (for non-empty sets; a blank set is created using set()), their mutable and unordered nature, the property of storing only unique values, and various operations (union, intersection, difference) and methods (e.g., .add(), .remove(), .update(), .intersection(), .union(), .difference()). The source also mentions set comprehension and frozensets (immutable sets).
Control Flow: Although not a primary focus of the initial overview, the source implicitly uses conditional statements (if, elif, else) and loops (for) in the Jupyter Notebook examples to demonstrate various Python concepts.
Functions: The source explains different types of functions (user-defined, built-in, recursive, anonymous/lambda, return statements) and mentions their coverage in the video tutorial. It also differentiates between functions (like len(), type()) and methods (called on an object using dot notation, like string.upper(), list.append()).
Modules and Packages: The source introduces the concept of modules and packages as Python’s way of providing strong standard libraries. It mentions using the keyword module to explore Python keywords and briefly introduces the pandas library for data manipulation.
File Handling: The source demonstrates basic file operations (opening, reading, writing, closing) for text files in Jupyter Notebook, along with functions like open(), close(), read(), readline(), write(), writelines(), seek(), and tell(). It also introduces different file modes (e.g., ‘r’, ‘w’, ‘a’). Furthermore, it covers working with pickle (for preserving Python objects in binary format), JSON (a common data exchange format), and CSV (Comma Separated Values) files within Jupyter Notebook.
Exception Handling: The try and except blocks for handling errors are introduced with a practical example in Jupyter Notebook.
Object-Oriented Programming (OOP): The source begins to cover OOP concepts with examples in Jupyter Notebook, including defining classes and creating objects, defining methods (including the special __init__ constructor), inheritance (single and hybrid), inner classes, and different types of variables (instance, class, static) and methods.
Recursion: The concept of recursion (a function calling itself) and the recursion limit in Python are explored with examples in Jupyter Notebook.
In summary, Jupyter Notebook is presented as an interactive environment that is highly suitable for learning and experimenting with Python programming concepts, especially in the context of data science, due to its ease of use, immediate feedback through cell execution, and integration with essential libraries. The source uses Jupyter Notebook as the primary tool for demonstrating a wide range of Python topics, from basic syntax and data types to more advanced concepts like file handling, exception handling, and object-oriented programming.
Python Data Types Explained
Based on the information in the source “01.pdf” and our previous discussion about Jupyter Notebook [Me], here’s a discussion of Python data types:
Python has several built-in data types that are fundamental to the language. The source categorizes these mainly into numeric, dictionary, boolean, set, and sequence types. It further elaborates on these categories, highlighting their key characteristics.
Main Categories of Python Data Types:
Numeric Data Types: These represent numerical values.
Integer (int): Whole numbers without any decimal point (e.g., -2, -1, 0, 1, 2). The source mentions that when you check the data type of a whole number in Python, it is shown as int.
Float (float): Numbers with decimal points (e.g., -1.02, 1.5, 5.86). If a number is defined with a decimal, Python considers it a float.
Complex (complex): Numbers with a real and an imaginary part, represented in the form a + bj (where j denotes the imaginary unit) (e.g., 5 + 7j). In Python, the imaginary part is denoted by j, unlike the mathematical convention of i.
Sequence Types: These represent ordered collections of items.
String (str): Immutable and ordered sequences of characters. Strings are defined using single quotes (e.g., ‘hello’), double quotes (e.g., “India”), or triple quotes for multi-line strings. They support positive and negative indexing starting from 0 and -1 respectively, allowing for slicing. Operations like concatenation using + and repetition using * are also supported. The source discusses various string methods (e.g., .upper(), .lower(), .capitalize(), .count(), .index()) and functions (e.g., len()). String formatting, skip sequences (e.g., \n, \t), and raw strings (using r’…’) are also mentioned.
List (list): Mutable and ordered sequences of items. Lists are defined using square brackets [] and can contain items of different data types. They support indexing, slicing, concatenation, and repetition. Due to their mutability, lists have numerous methods for modification, such as .append(), .insert(), .remove(), .pop(), .sort(), .reverse(), and .clear(). The source also introduces list comprehension as a concise way to create lists.
Tuple (tuple): Immutable and ordered sequences of items. Tuples are defined using round brackets (). They support indexing, slicing, concatenation, and repetition. Compared to lists, tuples have fewer built-in methods, mainly .count() and .index(). Tuples are often used for security purposes when the data should not be changed.
Mapping Type:
Dictionary (dict): Mutable and unordered collections of key-value pairs. Dictionaries are defined using curly braces {} with keys and their corresponding values separated by a colon : (e.g., {‘a’: 15, ‘b’: 18}). Keys in a dictionary must be unique, but values can be of any data type. You access values in a dictionary using their keys (e.g., D[‘a’]). Dictionaries do not support direct concatenation or multiplication like sequences. They have various methods like .keys(), .values(), .items(), .pop(), .clear(), .get(), and .update(). The source also mentions dictionary comprehension and how dictionaries can represent tabular data, leading to the introduction of the pandas library.
Set Types: These represent unordered collections of unique items.
Set (set): Mutable and unordered collections of unique elements. Sets are defined using curly braces {} (e.g., {5, 8, 7.9}). A blank set is created using the set() function, as {} creates an empty dictionary. Sets automatically remove duplicate values. They support operations like union, intersection, and difference, and methods like .add(), .remove(), and .update(). The source also discusses set comprehension.
Frozen Set (frozenset): Immutable and unordered versions of sets. Once created, you cannot add or remove elements from a frozenset. They support the same operations as regular sets but without modification methods.
Mutability and Order:
The source emphasizes the concepts of mutability (whether the object’s state can be changed after creation) and order (whether the elements have a specific sequence).
Mutable Data Types: Lists, dictionaries, and sets are mutable, meaning their contents can be modified after they are created.
Immutable Data Types: Numeric types (integer, float, complex), strings, and tuples are immutable, meaning their contents cannot be changed after they are created. Any operation that appears to modify an immutable object actually creates a new object.
Ordered Data Types: Strings, lists, and tuples are ordered, meaning the items in the collection have a specific sequence, and you can access them using index positions.
Unordered Data Types: Dictionaries and sets are unordered, meaning the elements do not have a specific sequence, and you cannot access them using numerical indices. In dictionaries, you access elements using keys.
Checking Data Types:
The built-in type() function is used to determine the data type of a variable. As shown in the Jupyter Notebook examples discussed previously, you can use type(variable_name) to see whether a variable holds an integer (int), a float (float), a string (str), a list (list), a tuple (tuple), a dictionary (dict), or a set (set) [Me, 6, 12].
The source highlights that understanding data types is crucial as it affects how data can be stored, manipulated, and the operations that can be performed on it. The practical examples in Jupyter Notebook, which we discussed earlier, effectively illustrate the creation, properties, and operations associated with each of these fundamental Python data types [Me].
Python Variable Identification Numbers in Memory
Based on the information in the source “01.pdf” and our previous discussion about Python data types [Me], here’s a discussion of variable identification numbers in Python:
In Python, when you create a variable and assign it a value, that value is stored in the computer’s memory. To keep track of where each piece of data is stored, Python assigns a unique identification number to each object in memory, including the values held by variables. You can think of this identification number as the memory address of the data.
The source explicitly mentions the id() function as a way to find out the identification number of an object (and thus, the value held by a variable). For example, if you have a variable a assigned the string “hello” and a variable b assigned the integer 5, you can use id(a) and id(b) to see their respective identification numbers.
Key points about variable identification numbers from the source:
Memory Allocation: A variable acts as a temporary container that stores data. This storage occurs in memory allocation.
Identification Number: Every piece of data stored in memory is assigned a unique identification number.
id() Function: Python provides a built-in function called id() that allows you to retrieve the identification number of an object. You pass a variable (which holds a reference to the object) to the id() function to see its identification number (e.g., id(a)).
Data Type Influence: The source demonstrates that the data type of a variable can influence its identification number. When comparing the identification numbers of a string variable (a = “hello”) and an integer variable (b = 15), a significant gap might be observed between their IDs. This suggests that different data types might be stored in different regions of memory.
Memory Allocation and Data Type: The memory ID released depends on the data type. Different data types might lead to different patterns in memory allocation and thus potentially larger differences in their identification numbers.
Small Integer Range: The source provides an interesting observation about the identity operator (is) and identification numbers for a specific range of small integers (-5 to 255). Within this range, Python might use the same memory location for variables with the same integer value. However, for values outside this range or for different data types (like strings and integers), different memory locations and thus different identification numbers are typically assigned. This behavior is related to Python’s internal optimizations for commonly used small integers.
In essence, variable identification numbers in Python provide a way to uniquely identify where the value of a variable is stored in memory. The id() function allows you to inspect these numbers, and you can observe how factors like data type can affect memory allocation and the resulting identification numbers.
Python Operators: An Overview
Based on the information in the source “01.pdf”, here’s an overview of Python operators:
The source introduces the topic of operators by defining them as symbols that are responsible for performing operations. It gives the example of 5 + 7, where + is the operator and 5 and 7 are the operands. The source categorizes Python operators into six main types:
Arithmetic Operators: These operators are used to perform mathematical calculations. The source lists the following arithmetic operators:
+ (Addition): Adds two operands (e.g., 4 + 7 results in 11). It can also be used for string concatenation (e.g., “hi” + “hello”).
– (Subtraction): Subtracts the second operand from the first.
* (Multiplication): Multiplies two operands.
/ (Division): Divides the first operand by the second, resulting in a floating-point number.
% (Modulo): Returns the remainder of the division of the first operand by the second. The source refers to this as the “modulo operator”.
** (Exponentiation): Raises the first operand to the power of the second. The source explicitly mentions this “double star” operator.
// (Floor Division): Divides the first operand by the second and returns the integer part of the quotient, discarding any remainder. The source highlights this “double slash” operator.
Assignment Operators: These operators are used to assign values to variables. The source provides the following examples:
= (Assignment): Assigns the value of the right operand to the left operand (e.g., a = 7).
+= (Add and Assign): Adds the right operand to the left operand and assigns the result to the left operand (e.g., a += 5 is equivalent to a = a + 5).
-= (Subtract and Assign): Subtracts the right operand from the left operand and assigns the result to the left operand (e.g., a -= 7 is equivalent to a = a – 7).
*= (Multiply and Assign).
/= (Divide and Assign).
%= (Modulo and Assign).
**= (Exponentiate and Assign).
//= (Floor Divide and Assign).
Relational Operators (Comparison Operators, Conditional Operators): These operators compare the values of two operands and return a boolean value (True or False). The source lists these operators:
> (Greater than).
< (Less than).
>= (Greater than or equal to).
<= (Less than or equal to).
== (Equal to): Compares if two operands are equal. The source distinguishes this from the assignment operator =.
!= (Not equal to).
Logical Operators: These operators perform logical operations and are often used to combine the results of relational operations. The source identifies the following logical operators:
and: Returns True if both operands are True. The source notes the importance of using brackets when combining and with other logical operators to avoid ambiguity.
or: Returns True if at least one of the operands is True.
not: Returns True if the operand is False, and False if the operand is True.
Identity Operators: These operators check if two operands refer to the same object in memory. The source mentions:
is: Returns True if both operands refer to the same object. The source notes it is similar to == but works with memory allocation. It highlights that for integers in the range of -5 to 255, is might behave similarly to == due to Python’s memory optimization, but this might not hold for values outside this range or for different data types.
is not: Returns True if both operands do not refer to the same object. It’s similar to != in that it checks for non-identity based on memory location.
Membership Operators: These operators test if a value (operand) is found within a sequence (e.g., list, string, tuple). The source lists:
in: Returns True if the value is present in the sequence. The source gives an example of checking if 5 is in a list.
not in: Returns True if the value is not present in the sequence.
The source also briefly mentions a bitwise operator, noting it is not much required for general programming but can be important in specific fields like electronics. It provides a resource for further learning about bitwise operators.
In summary, the source provides a foundational understanding of various Python operators, categorizing them by their function and illustrating their basic usage with examples. It emphasizes that practical implementation in a Jupyter Notebook (available via a link in the video description) is crucial for a deeper understanding of these operators.
Python Indentation: Defining Code Blocks
Based on the information in the source “01.pdf”, here’s a discussion of indentation and blocks in Python:
Indentation is a fundamental concept in Python that is used to define code blocks. Unlike many other programming languages that use curly braces {} to delineate blocks of code, Python relies solely on whitespace (spaces or tabs) at the beginning of a line to indicate which statements belong to a particular block.
The source emphasizes that in Python, curly braces are not acceptable for defining blocks. Instead, after certain statements that introduce a block (such as if, elif, else, for, while, and function definitions), a colon : is used, and the subsequent lines of code that belong to that block must be indented.
Key points about indentation from the source:
Defining Blocks: Indentation is how Python determines which statements are part of a specific block of code, such as the body of a conditional statement or a loop.
Colon Precedes Indentation: Statements that begin a new block of code are always followed by a colon :.
Four Spaces (Typically): The source notes that in environments like Jupyter Notebook and PyCharm, an indentation of four spaces is automatically taken after a colon. Other IDEs might default to two or eight spaces, but consistent use within a project is crucial.
Block Delimitation: The level of indentation determines the scope of a block. Statements with the same level of indentation are considered part of the same block. If a line is not indented at the expected level, it is considered to be outside the current block.
Example (from the source):a = 9
b = 8
if a > b: # Colon indicates the start of a block
print(“hello”) # Indented – part of the if block
print(“hi”) # Indented – part of the if block
print(“hey”) # Indented – part of the if block
print(“bye”) # Not indented to the same level – outside the if block
In this example, the print(“hello”), print(“hi”), and print(“hey”) statements are inside the if block because they are indented. The print(“bye”) statement is outside the if block because it is not indented to the same level.
Blocks in Python are sequences of one or more statements that are treated as a single unit. They are defined by their indentation level. Blocks are typically associated with control flow structures (like conditional statements and loops) and function/class definitions.
Significance of Indentation:
Readability: Python’s use of indentation makes code very readable and enforces a consistent visual structure, making it easier to understand the flow of control.
Syntax: Indentation is not just for readability; it is a syntactic requirement in Python. Incorrect indentation will lead to IndentationError and will prevent the code from running.
In summary, indentation in Python is not merely a matter of style; it is a core part of the language’s syntax used to define code blocks. Consistent and correct indentation is essential for writing valid and understandable Python programs.
🔥 Complete Python Course (Basic to Advanced) | Full Tutorial with Practical Implementation 🚀
The Original Text
nowadays Python programming language is booming day by day and it’s required for every industry in Automation in data science in data analysis artificial intelligence and many I made this course for absolutely for beginner from basic to advanc level in easy way and you’ll find it out the complete resource on a GitHub that link is available on description let’s first discuss what topic we’ll cover in this video so for first we’ll start with the overview where we will discuss about history and why should we learn a python what their competitor why should we learn a python for data sign if the lots of programming language is available then we’ll install the required software like py Cham Jupiter notebook anac iser software will anac iser providing the Jupiter notebook and spider so initially we’ll start with a Jupiter notebook and after that we’ll also discuss somewhere pyam as well depend on the requirement and then we’ll discuss about their basics of pythons like uh we’ll discuss variables keyword indentation commands so these are a topic we’ll first discuss and after that we’ll enter the very very important topic which is the backbone of data science data types so numeric string tle dictionary set these are data type this is the primary data type we can say we’ll discuss then and after that conditional statement and loop okay so all the uh Topics in a condition statement and loop will cover and after that functions so user defined function inbuild function recursion function Anonymous function return statements so lots of topic is there in a function will cover each and everything and then package and modules so python become strong because of large standard libraries so library is made with packages and module so we’ll discuss that topic as well so user Define predefine and find search path and some names SP lots of topic is there we’ll discuss in this video tutorials so we can say these are a topic it’s a Basics and intermediate and advanced python is also there which one is file handling will discuss exception handling objectoriented programming and multi-threading let’s discuss about the complete overview of python so here in the market so many languages is available but why should we learn a python right so our entire tutorials is a focused on the data science I’ll take the example of the data science and uh in that direction we’ll discuss so basically machine learning and artificial intelligence obviously it comes under the data science will build on the mathematical principle like a calculus algebra probability statistics so we have to choose those programming language which is very much compartible with this mathematical concept because because nowadays the this Ai and automation concept is booming right so we have to choose those language so python obviously is the best for them but what is the reason before going to the python let’s understand the concept of the machine learning okay so machine learning basically a application of artificial intelligence when a machine can learn automatically from the previous experiences let’s say for example you meet a person after 5 year okay and suddenly you start predicting that the person can be the Priya Raju and moan any any name you are just start predicting and how we able to predict predict it the reason behind that because that kind of pattern is already store in your brain so accordingly you are predicting okay so in a real life so we have the large amount of data let’s take example of Instagram so Instagram the huge amount of data they are recognizing the pattern and accordingly is giving the suggestion to you right so in that algorithm in that pattern Rec in pattern calculation we required a those programming language which should be compatible with the mathematical concept so python is one of them but why python why only the python why not other like only the python can be used in the data science the answer is no we can use the any programming language language in a data science in a machine learning but we have to choose those which is comfortable with mathematical concept so let’s understand that so in a real life there is a two type of categories there of a programming language the first one is a static and the second one is a dynamic what is a static static in the sense so we’ll take example of java in a static and python as a dynamic okay Java is a static programming language and python is a dynamic programming language so basically we are writing uh Java like uh in this this is the script of a Java we’re writing the code but here when you’re assigning the value is 9 uh in a and four in a b so after the calculation a divide by B the answer should be the 2.25 but you’ll get the answer is two the reason I already defined the data type okay Define the data type which is a integer because of the integer it will print only the two so what is the concept behind that because it will take the values the 2.25 it will take the inputs but after translation after the translation it will start comparing the target values which is the C this is the target variable and value is a 2.25 comparing with the input values which is a in C after comparing whatever values we get it and that is showing as a result which is a two all right so the translator in a Java programming language we are calling the compiler okay so compiler is nothing but a translator not in a Java in every programming language compiler is exist but in a Java we normally calling compiler in a python we have a different name but the compiler is there a different name is is inter uh interpreter okay so we understand that the Java is a static programming language but how the python is working so python is a dynamic programming language it directly take the inputs translate it and getting the result how basically is working you can directly assign a is equal to 5 b is equal to 8 and C is equal to B / a and when you just divide it you’ll getting the proper decimal values I’ll I’ll show you some real example okay I’ll show you some real examples so that you can easily understand suppose I have a value is a is equal to 5 b is equal to 8 and C is equal to B / a and get the value C that will getting 1.6 that is the proper floating values but when you just take the data type of a you’ll get the values is integer when you check the data type of B you’ll get the uh data type of B which is a integer but when you check the data type of C which is a float automatically converting the data type so the conclusion is that in the static and dynamic in a static programming language we have to take care about the data type where the dynamic programming language we don’t need to take care about the data type but again so as I said that the every programming language have a compiler means the translator have also the compiler but why it’s not comparing you the input values the reason behind that so whatever source code you have so again the compiler will help you to convert your source code into bite code and there is a virtual machine is available in every programming language like in a Java we we have a jvm in a python we have a pvm python virtual machine so here the compiler and virtual machine is running together that’s why we are directly getting the answer and in a jvm jvm the translator and virtual machine is a running separately so that is the reason we are getting the result based on the input values so which one is a dynamic programming language which one is a static programming language we can say the python JavaScript JavaScript and Java is both are a different language script and Par language and Julia these are a dynamic programming language where is a Java C C++ these are a static programming language okay so these are all these all are a dynamic programming language are matlb Julia SAS JavaScript scalap python this all are a dynamic programming language then again why we choose a python right for a data sici why not we are choosing the r language why not a mat Li so again these all are good to choose uh um uh for data science but every programming language have a limitation python have also the limitation but it our label almost every field if I want to use a Python programming language in the web development via Jango and a flask we can you easily implement the web application if I want to go in a cloud infrastructure that python option is available the data analysis is there in a testing field is there so almost every sector python is available because when you go in a Technology field so it’s not like that you’re you’re doing the analysis on uh you know some uh some PP and dashboard you show in and finished no behind that the lots of pipeline is running so in the pipeline so python is also very good in a data engineering as well so that is the reason python is become very famous and most of the companies are using this python so let’s conclude it what exactly the python this this will be the definition of a python so python is nothing but whatever discuss we’ll just summarize it here so python is first of all high level programming language high level in the sense those language which requir the translator is a high level so almost every programming language is a high level there is two language is a low level and high level low level in the sense machine language which is a binary which computer understand but we are not writing the code in a binary format we writing the code in the normal format like A + B / by 2 so it is a high language source code for computer the high language is not for human not for a student it’s for a computer the computer is saying that hey I understand only the binary and you’re writing something so I need a translator so that is the reason the computer is saying that it’s a high level second one is interpreter language which we just discussed and uh uh for translator we are using this interpreter and uh dynamically type language okay just now we discussed and it have a large standard libraries almost every field the python is available just because of large standard libraries okay so for if I want to do anything just have to install and start implementation it’s not like like that easy but yes the option is available to work in any any uh domain with python so it’s a portable portable in the sense it’s comfortable with any operating system we can use with the uh Windows Linux and Mac so even in the Linux it’s by default the python is available the reason behind that I’ll discuss in a history of python okay but it’s a comfortable with uh all the three operating system a the main thing of the portable language is that suppose I wrote a program in uh Windows operating system and one of my friend is using uh Mac or uh Linux so they don’t need to change any kind of environment they can directly use it if they have a python okay so that is a meup portable it have EXT uh extensibility features in the sense inside uh python I can also write the r language I can write a Java language J python option is also there so we we can extend our Python programming language so python is also supporting the objectoriented concept which is very very important for a software development almost 99% of software is making with objectoriented Concept so that is the reason Java is become very very famous because of this oops concept and again the last concept uh last topic is a free and open source free means you don’t need to pay anything open source in the sense so that source code is available for us we can also check it okay so whenever you install the python that any if you have any libraries like if you install the pandas okay which is famous libraries for a data science if you install the pandas so behind the pandas uh whatever source code is there we can also check it so that is the meaning of source code so let’s discuss about the history of python so history of python is very interesting uh like U um the python is old language or a new language uh in nowadays the two languages are very very famous is Python and Java right so Java is is a versatile language like almost every field is available it’s capture the market um it but the people are thinking that uh the Java is old but answer is no Java is not old python is old those who made the python the name is a good when rasim goo van R so this guy is made started implementation in 1989 so he was a mathematician he was a very uh you know famous mathematician he got many medals in the mathematics uh he did a masters in uh mathematics and computer science so he start doing researching in the mathematics so his main focus was that to um you know solving the mathematical problem so when he started the uh python in 1989 when the Java comes in the market is the 19 1996 1996 okay so it started in the 1989 and uh and he released the first he released the first version is is python 0 .9 which supportable for one andux after that he released for everyone he released for everyone and uh uh you know that be supported for Windows Linux and uh uh Mac all the operating system and this um the Python programming language is start becoming famous after 2000 okay when he released the 2.x version so even nowadays we also confused that which one we have to use 2.x or 3.x that I’ll discuss uh after this after this history so here when he release the 2.x this Python programming language is properly enter in uh software development field before that he was this programming language was in research field in uh mathematical research you can say uh so before the Java is entered in a you know in um a software development field that’s why we think that the Java is very old but actually the python is old programming language actually this guy is working in a many famous companies like uh Google Microsoft Microsoft and Dropbox so these famous companies is worked on it so python has become famous when he was in Google he was in Google in a 2000 5 to 2012 2005 to 2012 he was doing half of the work to developing the python so when he released the 3.x version of 2008 so that time the python start booming in all over the world especially in the data sign and artificial intelligence field because the Google company already doing a lots of research in artificial intelligence so he got a very good opportunity and uh python we Implement python is become The Versatile programming language and the people I start using after 3.x version so sometime we confuse that what is the difference uh between the 2.x and 3.x actually when he released the uh 2.x version 2.x so he forget to implement the object Orient concept so later when he try to implementing the object oriented Concept in a 2.x so the P the programming become very unstable so that is the reason uh he started a 3.x version and even the many people already started the 2.x that’s why he didn’t deleted that uh version but we can say the 2.x is a kind of Legacy but if you are a new if you are a beginner it started the uh this Python programming language so obviously you have to use 3.x you don’t need to use 2.x okay because when you write the the syntax of the Python 2.x and 3.x is a little bit different so like if you want to write a p uh print statement for example uh print hello world hello world so in a threo x we are writing like this but if you want to write in a twoo x so you have to write print double quotes hello world so there is no any bracket so the syntax is also different because the 2.x is not completely supporting the objectoriented programming language installation of Jupiter notebook we have a multiple option is available you can choose anything so like we have a anaconda let me just change the color yeah we have Anaconda we have a minond okay so multiple option is there so uh even you can directly uh install the Jupiter notebook via the command prompt as well but we will choose the Anaconda okay because Anaconda is giving the three options uh for a data science which is really useful for us so you will find it out a jupyter notebook first okay you’ll find a jupter notebook and you also find it out the spider which is very helpful for uh data science even uh in Anaconda is a pre predefine the many libraries so which you don’t need to install it like a pandas naai M plotly this libraries is preinstalled you don’t need to install it separately so many uh option is there so you can use it so we’ll install here the Anaconda and after that we start the installation solution of spider and Jupiter notebook so let’s do that so you can directly go to the official website anakonda just go there you’ll find it out the free download option just click on download that’s it your downloading process will start when you just check it let me just cancel it this my my downloading is already um on I put on a run so it will taking a Max to Max 1 minute to complete it and after that I’ll start the installation so yeah downloading process uh is completed I think so I can also check it in a download no it’s still downloading I think it’s taking ah now it’s downloaded so you can go there it’s showing the uh this icon double click on it it’s very simple just double click on it okay so it’s verifying and just click next I agree just me next you don’t need to change anything just next install you can just add the uh anakonda 3 in your environment if you’re not adding it’s not creating any problem just click install that’s it now it’s completed I think just click next so you can see here the Anaconda Jupiter notebook logo is mentioned there just finish it okay it’s giving the for uh registration for free and so many option don’t do anything just close now back click on Windows you’ll F and all app whatever which one you are using Windows 10 Windows 11 you’ll find it out the Anaconda 3 folder so where we have a anaconda Navigator where in case if any jupter notebook or spider anything is not working properly go to the anakonda navigator that work like a setting and you can use it so anakonda prompt is a kind of command prompt okay so I think it start opening the anakonda Navigator even I I’ll show you as well so in this anakonda prompt you can install any libraries with Pip or k environment so this is like a uh prompt which we have a local machine as well so this Anaconda is provided their own prompt okay this one is the Navigator let me just close it this one yeah Navigator the so many option is showing in case if anything is not working you can launch it from here like py Cham or um yeah py Cham professional R studio so many option they are showing but you don’t need to do anything this one let me just close it okay back to that uh folder again Anaconda 3 yes so you’ll find it out a jupyter notebook and a spider you can just open on it so for Jupiter notebook you can open from here or else you can directly search Jupiter notebook okay will search Jupiter notebook in this location so automatically the Jupiter notebook is opening on the default location which is uh it’s showing the uh prompt here it will open the uh Jupiter notebook in this location C drive you can see the serving notebook from the local directory C user your PC name all right so you can check it so where is it store opening so always opening in this location so my jupyter notebook is open here you can just directly click on new Python 3 and start writing the code is here sometime your jupyter notebook is opening on a you know Chrome or sometime opening on a Internet Explorer so which one is your default um uh web browser okay so you can write here print hello world let me just type it here hello world and click on run you’ll get the answer here so now Jupiter notebook is a properly installed let’s discuss about the third module basics of python where we’ll discuss about variable keyword indentation data type commands and lots of things the very first one is a variable variable is nothing but a memory allocation which store the data according to their data type okay for example I have one one data I want to store somewhere so we need a container right so variable working as a temporary container which store the data and we need a data type to Define that so if you storing the data and is defined with a data type like hello stor in a five store in a b so hello is store according to string data type and it is storing in the variable a five is storing in a b according to integer data type so whenever we Define the data types it it release the identification number so every data is storing in memory allocation and Define the identification number let’s understand with the uh practical implementation so I already created the proper Jupiter notebook file you can easily find it out on a description in the link that Jupiter notebook file okay so hope you know that how to open the Jupiter notebook in particular location so I have created my proper folder so file is available Basics so when I click on there so I can easily open my basic file that’s i p ynb file we can say jupit notebook file let me create a new Cale and write it down here no normal variables like a is equal to hello so when I click this button I can easily run it and when I just check the data type so there is a function predefined function is a type so even the type this topic is there function so where we’ll discuss we’ll create a function as well to check that what exactly the data type we are using the type of a so that’s a string data type when I check that b is equal to 15 and check the type of B then you can find it out it’s a integer data type and python is showing as a int so now as I said variable is nothing but a memory allocation if it’s a memory allocation which store the data that means it release some identification number as well so we can easily find it out like a ID there is the ID function where find it out the identification number when I pass ID of a so you can see here this is the ident identification number okay when I just check the ID of ID of B that is a identification number of your B variable and a variable actually the when you see the differ between the Vari variable a and variable B so lots of Gap is there because a is a string data type whereas B is a integer data type suppose I have a variable um C is equal to 0 and check the DAT uh check the identification number so ID of C this is the ID of c and a simultan I’m also checking with idea B then you’ll find it out the lot Gap is not there Gap is there obviously because the number is a different so when I just check it here you can see the last few digit is only change okay last few digit is only change but when I check with this one the lots of Gap is there reason we change the data type so it release the memory allocation memory uh ID depend on their data type if I’m taking the different data type the that will also be number D is equal to 19 + 19.8 and check the ID of D that will be the uh different identification number it’s not only the few digit is change so lots of values change also reason we change the data type because the D is a floating data type when I just check the type of d That’s a float data type so these are a variable hope you understand how the variable is working but I as I said when I Define any variable like a b is equal to 15 and it store the data according to the data type so now what is a v uh what is a data type so in a Python programming language the lots of data type is there so here python have a main category of the data type numeric dictionary Boolean set and sequence type where we have the main data type is a integer complex and Float integer complex and Float okay so we have also the another data type like a dictionary bullan set is also there and set oh yeah set is there string list and tle that’s comes under the sequence type so these are nothing but just a category so in the coming videos we’ll discuss about very details with each and every data type dictionary set string taple each and every data type will discuss in a very details way but let me just show you how the list is look like how the uh you know uh tle is look like how the string is look like so as you already see that how the integer look like if any number which Define without any decimal that’s a integer so here so data type we have different different data type is available like uh we have a string like if I’m defining with a double quotes so like hello here so that’s a string data type you define B is equal to in square bracket that will consider as a that will consider as a list if I Define with a round bracket that will be considered as a tle if I Define with the curly brasses curly brasses directly passing the values that is considered as a set if I Define the same value with key value pair is equal to key value pair like 5 colon 4 uh 4 colon 7 and 9 colon 8 so if you define like this that will be considered as a dictionary okay so that’s a dictionary that’s a set okay so what exactly the mean of this hash this hash symbol hash symbol is nothing but a comment we are defining as a comment so that’s a set that’s a topple that’s a list okay so these are a different different data type and this one is nothing but a string so in the coming video we have to discuss in the very details of each and every data type now let’s discuss about the keyword what exactly the keyword so keyword is nothing but a reserved word which can be used for only specific purpose and cannot be used as a identifier let me just write it down keyword keyword is reserve word which used for one specific purpose fake purpose cannot be used as a identifier cannot be used as a identifier now the question is what exactly the mean of identifier let me make as a uh markdown so that markdown in the sense it will taking one statement it will not consider as a code okay normal statements so cannot be used as a identifier so what is the identifier identifier so identifier in the sense any variable name any um you know uh function name okay any variable name any function name any class name that will be consider as a identifier class name that will be considered as a identifier okay so now the question is how many Reserve word is available in Python programming language so here in the lots of Reserve word is available but U to check that how many Reserve word is there so there is one module is called as keyword module keyword module keyword module and when you pass it here keyword do KW list then you’ll find it out how many keyword is available for false none true the lots of keyword is available is Lambda lots of keyword is there which is stored with a square bracket one container and that container we are calling list okay so as I said keyword is a reserve word which is used for only specific purpose cannot be used as a identifier used as a identifier what exactly the mean cannot be used as identifier like if I’m creating any normal variable able okay let me create one normal variable my variable name is a equal to 8 so I can easily Define it to not create any problem we can easily Define it here a is equal to 8 can I use uh any keyword like uh if I’m using if Okay small i f if we are using IF is equal to 8 can I define it like this no it will giving the error because because this if is reserved for only the conditional statement you can’t use as a identifier you can’t use as a normal variable so if is used for one conditional statement like if L if else true false is used for one bullion purpose okay so uh class is used for only object oriented break is only for breaking the loop so these are a reserved word which cannot be used for a normal purpose now I want to see that how many Reserve word is there I want to check that how many values is available first thing is that you have to just calculate one by one so this is the uh not a right way so the better is we can use like this there is one function is called as alen length which which will be count each and every element and tell you how many element is available in that container so I’ll use the keyword KW list and when I run it will showing you 30 five keyword is available okay so whenever you using any uh ideally right now I’m using the Jupiter notebook ideally so that time you can easily check it and uh you know the future definitely the python will increase the keyword okay so right now I’m using Jupiter notebook which is considered a 3.9 version which have the 35 keyword is available hope you understand this keyword now let’s discuss about indentation what exactly the indentation indentation in the sense is Define the block I have some program uh like if program uh conditional statement program if a is greater than let me first Define it a is equal to 9 and B is equal to 8 and I have a program is if a is greater than b okay so in other programming language we are using the curly brasses and put inside a statements so here curly brasses is not acceptable so we have a indentation we have to use a colon after the colon it automatically taking the four space okay automatically taking the four space if I’m writing here if you’re going with any other ideally uh maybe it will taking a two space eight space but in a Jupiter notebook and a py Cham is taking the four space if I’m writing here the hello okay so if you want to Define anything like hello if I’m writing here and hi if I’m writing here and he if I’m writing here print he okay this hello hi hey yeah we can say line number 5 six 7 that’s comes in if block so defining the block we are using if uh colon and automatically taking the for space if you’re using the back space and write it down here print by so that line number nine will consider as a uh outside of the block so that bu is not in if condition okay by is not in if condition so here we can see we are using by outside of the block because I I’m not using this four spaces so that’s called as a indentation if you have a single line of commands so we normally using like uh I have a statement is a print hello world and just use the hash if you’re using the hash it will be considered as a single line command like if you run it here you’re getting the answer is hello world I’m using the hash it here so it will making as a comment so single line comment we are using hash and for a multi-line comments suppose if you have multi-line of statements uh I have a same thing yeah this one I want to make a comment so for that you have to use a triple codes 1 2 3 okay start with triple codes and end with 1 2 3 normally when you just run it without using this triple codes it will showing the answer perfectly showing the answer hello hi whatever the program is there accordingly showing the answer but if you’re using the triple codes one 23 and one two 3 run it you’re not getting the answer you’re not getting the answer here actually it’s showing the as it is statements uh this triple quotes is also used for string as well so in a string time we’ll discuss that okay but it is also used for a multi-line commands so this one is a single line commands and this one is multi-line commands we are also using the double triple codes like this one this one okay so we also using a double triple Cotes so it’s a multi-line commands we are using that’s the same thing but we mostly using this hash for a single line comments if you have the multiple lines we using the multiple lines as a single single line of comment with hash now input and output function so suppose if we have any normal uh function like Y is equal to 3 x + 5 so mathematically equation is there I want to apply some input and output function in this equation so where X will working as a input because when you are passing the different different input like 2 3 4 if I’m passing two so two 3 6 + 5 11 when I passing different different input accordingly you’ll get the output so here let’s take X as a input X I’m taking as a directly 8 Y is equal to 3x + 5 3 3 into x + 5 3 into X so Define the multiplication we are using star symbol x + 5 and I want to display it so for a display for output purpose we are using the print statement print function I’m writing here x so when you run it this one run button or else we have a shortcut is a shift enter when you click this cell you’ll find it out the shift enter run the cell and select below as well I’m using it here shift enter okay shift enter so it will showing the answer is eight now I want to this one as a user input so we can take is a input there is a input function and pass the statement is enter the value of x take a space so this one will taking the proper user input and pass it here 3 into x + 5 and accordingly generate the answer is 8 if I’m passing uh you know two isas here so let me just run it asking the question enter the value of x I’m passing the value is a five I’m expecting that three 5 15 + 5 is a 20 but it’s showing the error reason because this input function by default taking as a string so in saying that cannot can only concatenate with a string to string not to string with integer actually the X variable is taking as a string when I just Che it here type of X that taking as a string and X is taking as a string three is a integer so cannot be multiplied with string and integer so we have another function is int so likewise other data type like int float complex we have a function as well I’m using int open the bracket and close it here when I run it it asking the question enter the value of x I’m passing here five then it will be calculate and showing the answer is five now I want to Define it properly uh like result is five so the result is five is the statement I’ll Define in the double quotes result is and then five will display here so result is is nothing but your double uh statements or string and is your number so we have to separate it with a comma when I run it asking the question enter the value of x 6 so um sorry not to display uh X we have to display y let me run it again enter the value of X4 and accordingly is getting the answer is 17 now this time when I just check the type of X showing the answer is integer not to string okay so where X uh X is taking as a input we took the in function is input function so this is the input and this one is the output okay this one is output So based on this uh input output and uh variables so I Define the exercise so you can easily find it out description in this video and that uh exercise is also available you just run it then you’ll understand with a different different scenario of variables data type and input output function continuing the basics of python last topic operator is remaining let’s finish in and after that we’ll discuss about the next topic is a data type so operator is nothing but the symbol which is responsible to do any operations for example I have a five + 7 so the plus is a responsible to do addition operation so this one we can say it’s operator this one is operator and five and seven is called as a operant operants okay so there is so many symbols is available in the programming language so we categorize in many way so that categorize in such a way so that we can easily remember it so there is a six main operator is remaining the first one is arithmetic operator assignment operator relational operator logical entity and membership operator so one operator is also there is a bewise opor which is not much required for um for pro as a programming perspective if you belong to the any edic field so that time is really important but still I’ll give you the resource where the bewise operator is also available so you just run it you will also understand the beat wise as well but this main operator list try to understand it in a theoretically and practically both the way the first one is arithmetic operator as I said that the symbol are available plus minus the star so I think you guys is already aware about that so the meaning of the plus is nothing but using for addition minus is for subtraction so we can directly use this kind of symbol so only this double star uh modulo that percentage symbol and double slash is something new for you so let’s discuss about that and we’ll also discuss some um you know uh this basics of this operator as well in a very short way let’s jump on a practical implementation like if you’re writing here the 4 + 7 then you’ll get the answer when you just run it you’ll get the answer is 11 so plus is a responsible to do the adding two things adding two numbers right but if in case if you’re using this both the this operator Plus for a string like a hi plus hello which is responsible to do the concatenation that we’ll discuss in the very details in in string topic but plus is responsible to do some operations right I was discussing about you know the modulo operators and uh uh uh and flow division operator so I have created the complete uh you know Jupiter notebook file so you will find it Out Below um below this video you’ll find it out the link you can go through it and just run this file you can see here what is the mean of plus minus everything is there I properly created here you just click here and run it you’ll find it out the answer in case if you find it out any confusion anything you can just put the comment below okay so everything just you have to run it you’ll understand easily this how the symbol is working right so this is the arithmetic operator and uh when you go to the next operator so that we have assign assignment operator assignment in the S assigning the values right if I’m writing the a is equal to 7 the meaning is that 7 is assigning to the a right so but if you’re writing the a is equal to is equal to 7 that is meaning is totally different you are comparing a with seven so here the assignment operator is available like uh uh when you just use a equal to 7 at the same time if you’re using A+ is equal 7 the meaning is that plus is equal to 7 is that a + equal 5 is meaning is that a equal a + 5 so again you will understand very easy way if you’re doing the Practical okay so I’ve created the uh all the assignment here all the arithmetic operator if you’re using is equal to like minus is equal to Star is equal to SL equal you’ll get these values a minus equal 7 is equal to a = to a – 7 right it’s very simple way go back to the Practical so here you’ll find it out the assignment operator as well so like here a is equal to 5 and B is equal to 3 I have assigned it where is that here short shortcut key to run this U jupter notebook shell shift enter so a five is assigning to the A and three is assigning to the B A is equal to a plus b so you’ll getting the answer is a whatever values is of available five + 3 that 8 will be assigning to the a you can see here but B you’re not assigning anything so B will be the original values which is three right this all the values I have just created you can you can perform with all the operation all the combination you’ll find it out in confusion you put the comment you will find it on on a GitHub we will put the comment or uh uh YouTube itself you know comment you can put it I’ll reply you okay I consider that is very easy things because in our school days we already learn this kind of things addition subtraction multiplication so only this module and flow division is something new for you when you just run the jupyter notebook you can understand easily let’s talking about the third operation third operator sorry not operator operation third operator is a relation relational operator somebody is also calling the comparison operator because you are comparing a isal to 5 is there b is equal to 7 is there if you’re writing a greater than b you can also write B is less than a that means you are comparing the answer is always The Logical format what is a logical logical format can be true can be false true or false answer right your answer will always be the true and false concept you comparing like a is less than b a is greater than or equal to B this is the symbol for not equal to this symbol for not equal to this is symbol for equal to equal to in the sense a is equal to 5 is already assigned let me assign some other values uh C is equal to 18 and D is equal to again 7 okay so if I’m writing the C is not equal to a so obviously C is not equal to a right so you can see you’ll get the values is true because C is 18 and a is five which is really not equal to True uh not equal to uh both the values you’ll get the answer is true it’s really not equal okay so this kind of thing is mostly using in the conditional State this name have also one more name is a conditional operator yeah have this one have a three name relational operator comparing comparison operator and the third one is a conditional operator conditional operator okay so we can provide the condition and you’ll get the values is either true or false answer go back to the Jupiter notebook you can just perform the operation like here when I just run it uh result is always in the bullion bull this this value is a bullion okay this values is a bullion logical in the sense logical is a operator where true and false is the value is a bullan values again uh see the next operator is a uh logical operator this concept will be clear okay so a equal to equal to B A is less than greater than when you just run it you will get the either true or false answer why it’s a is H so A and B is not the same that’s why it’s giving the answer is false a is greater than b so the answer is giving the true a is not greater than b okay maybe I didn’t run the this command that’s why yeah it’s taking the previous A and B values you can see here a is not equal to equal to B I wrote it that getting the answer is false where a is greater than b so a is five and B is a 7 that giving the answer is false because five is not greater than 7 okay if is not equal to you can also write the concept like if uh uh a equal to equal to 5 actually the a is a five I assign the values and I’m also writing the five when you just run it you’ll getting the answer is true okay the next operator which I discuss in this uh uh operator as well let me just remove it the next operator is uh yeah okay so next operator is logical operator as I said that this is always giving The Logical format we can say the value is a bullion true and false is a bullion okay logical operator is and or not okay and or not so a b let’s consider as a variable and if your value is a true if a is a true B is a true so A and B become a true so this is the rules which you are following in The Logical operator it is there in uh physics and Mathematics everywhere in a programming language we are not changing anything whatever you learn in engineering or uh 12th so that is the same thing here so A and B if anything let me just remove if anything is a false that will be the false see here true false that value will be the false in case if the value is true and true and false the answer will be the false if any one values is a false and operator will give the values false here is a false that’s why it become false if everywhere is a false like here and here is become a false or operator is a totally opposite if anywhere is true giving the answer is true so here both are true that’s why is true one is true that’s why is it true one is a true that’s why is a true and false both the places have a false that obviously it become a false okay so where when you’re talking about the not operator is a totally opposite false to true true to false go back you can find it out the Practical as well so you can see here I performed the lots of operation here so here it’s uh uh something interesting so here I assigned the values a b c c and a both are a same values here I assigned a is greater than b so which is a buan values that can be true that can be false So currently a is greater than b which is uh obviously uh you know it’s a false because five is not greater than C and B is greater than C with seven is greater than five that is all that is true so false and true that become a false so likewise you can just run it you’ll find it out the values not operator is a totally opposite right so not operator like you getting a false this one become true okay so here sometimes a confusion is that uh we use the this symbol and sometime we use this symbol what is the confusion both are same or both are different okay let’s discuss that so to discuss that so we have to go a little bit in bewise operator as well so as I said that it’s not more important as a programming perspective but you should know about that you don’t need to go in a very details way because the beat wise operator is very very big concept okay so here um we have a two symbol we have a a and b and we have a this one as well we have a o r we have a this one as well we have a not we have this one as well so this one we can say it’s a logical values logical values and this one is a b binary values uh B twice values okay this one I can say logical and this one is say the beat wise values so if you write the values is like this let me just compare it suppose the a value a is uh you’re writing here we already have a ABC right so the a uh through okay a is greater than b which is uh false and B is greater than C which is true then getting the answer is a false but when I just go with that this uh different symbol and symbol this one you also become false I have to get some example where getting the opposite values then I can explain you in Easy Way ah I think this one is the best one 15 is greater than 16 which is a false 5 is less than 8 that’s it true so it here the giving the answer is false because this one is a uh this one is a false and this one is a true so answer become a false so when I just perform the operation is here here is the and symbol and here is the and is giving the different answer what is the reason it’s giving the two different answer as I said that is both are very similar not the same okay so so but if I’m just use the bracket here you’ll get the answer is false what is the difference here so don’t be confused anywhere you can use and anywhere you can use and symbol the only you have to take care about the brackets but why is Valu is changing first I’ll just explain you and after that I’ll go to the next operator okay the value is changed because so you can see here the and operation is directly apply The Logical right this one is taking a true uh this one is taking the false this one is taking the true this one is a true this one is a false but when you’re talking about this one so actually it will be in because of the order wise so preference of this uh uh relationship operator like less than or greater than is a below as compared to this so this one is a bwise operator the actual the 16 and five is uh apply the operation and getting some different number how it’s working I’ll show you okay why it’s not removing okay sorry so you can see here let me just remove first okay you can see here if I’m just perform the operation is a 16 and five you’ll get the different values right 16 and five and when you just perform the operation is a 16 and 5 you’ll get a zero why is it totally different the reason behind that when you just perform the operation the the 16 and five will converting in the binary format so uh there is a proper concept is there like uh the 16 if you want to convert in a binary so uh we have the binary format like uh uh Power of Two only so 2 to the^ 0 2 ^ 1 2 The Power 2 2 The Power 3 like this so this one become a 1 2 4 and uh this one become 8 so if you find it out the value of 16 okay and this one will be 2 to the power uh 4 that will be 2 2 4 2 8 2 16 so when you’re talking about the binary concept so you’ll get the value is somewhere around 1 0 0 0 0 that is a 16 and when you’re talking about a 5 so 4 + 1 become a 16 so 1 0 1 one then it perform the and operator so I’ll not go in a very details way the explanation of how the number is converting the binary and then performing the operation there is a lots of function is available not a lots of Function One function is available to explain this concept okay so when you just use the bin of 16 you’ll get this 1 0 0 0 and when you just use the bin of five you’ll get this and it will perform the operation and and operation 0 and one is become a zero right 0o and one become a zero so when you perform the operation here you’ll get a two different number that is the reason is giving the different values so avoiding this kind of confusion the conclusion is here avoiding this kind of problems we always use a bracket if you’re using this and symbol okay otherwise to understand in very details way I can make a separate video I’ll not go in a very details one here so you can just run is the bwise operator how the number is converting how the value is performing the add operation and or operation okay so here I just giving this some example you can use it I’ll go little bit details here you can just run and you can understand I wrote it just now 4 hours ago you can just use it let me discuss the last two operator which is uh identity operator and one more operator is there which is the membership Operator Let me just remove this one again if you want to know in the very details of uh dewise operator I can make a separate video for this but this is not much required for as a programmer because we already have a function Okay so identity operator is very similar to the equal to and uh uh is not is very similar to not equal to so it identify the values like a is equal to 5 and B is equal to 7 and C is equal to a five again so a is C so it very similar to the equal to equal to it also giving the bullan answer okay G given the bullan answer which is a true and false bullan is nothing but a true and false values that we are calling bullan values membership operator membership operator is in not in okay the value is a particular member variable or not suppose I have one variable which have a list is a 5 7 8 9 so five in a or not like this practically you can easily understand so identity operator is basically working with the memory allocation which is is or is not let’s say for example here I have some values when I just run it so a equal to equal to B which is a five and 7 is getting the answer is false but a is B is also giving the answer is false which is correct a is not equal to B we can also make it similar as a is not equal to B but again this operator is working for the minus5 to 255 range only if you have the values more than that that time this is and not is will be not be similar as uh not equal to and equal to I have this values you can get the values is true 7 and seven but again you have a two different values which is a uh 399 okay n and making equal to equal to You’ll getting the pro but n is M the answer is no the value is different so uh the last video I have explained about ID how the memory allocation is working in a variable concept when you just see the V uh the memory allocation of n will be the different as memory location of M so minus 5 to 55 the range the memory allocation is working the same where is this one is working not same okay same thing here so you can see if the value is this one a uh G is equal to the big statement if the memory location are same then it will be considered as equal to the whole conclusion of this identity operator is that this identity operator working with a memory allocation if the memory loation are same it will be say that is and if not same is not okay you can’t directly uh say that the is is nothing but equal to is not is nothing but a not equal to is and is not working with the memory basis and equal to not equal to working with a number basis value basis the last one is a membership operator as I disc as I said it’s uh the particular value is a part of the member or not so in and in not so here I have a big list and checking that a five the particular member or not so saying that yes it’s member but 77 no so but I wrote the statement is not in see the Python programming language is very similar to the English language right so the whatever operator whatever uh statement you writing is will be it’s uh you know the state have some sense it’s not like that whatever here is writing the in here is a not not like that it’s a proper statement in not uh sorry not in okay in not is not make sense but not in have a sense is it true and so likewise I also perform some operation like um the t u a i displayed in the you know the sequence wise here I will not explain that why is display in the sequence wise it’s a for Loop okay so the coming video you can easily find it out how the for Loop is working in the Practical and theoretical way with the flowchart I’ll go in a very very details way okay so I request you please run this all the operators uh all the operator I’ll share with you these files on a GitHub you just download it and run it we entered in a fourth module which is a data type so we already discussed the last uh we already discussed the data type in the last video so I think this PP you already aware about that because in last video the overview of python I already discussed right so what is integer what is a complex what is a float so the data so many data type is there especially in a python so you’ll find it out some some new word like the set set string list tle and dictionary is also there just not there in C+ plus Java and C language so which is something new for you so in this uh from from this uh modules so we will discuss in the very details of the data type right in the last video we just give the overview so here we have to enter in the depth of the data type and see the data type is very very important concept for a interview perspective because 99% probability that the interviewer will ask the question related to a data type actually this data type is using in almost every places if you are making any application with a Python programming language uh this data type like um uh it’s easy to implement it’s easy to understand but you can easily forget as well the reason because this small small topic is there okay it’s not much difficult we’ll learn it one by one and we’ll make the proper structured way because of the lots of data types so python is creating the data type uh with two different categor the first one is immutable data type the second one is a mutable data type so which one will consider as a immutable data type like a numeric numeric data type numeric data type will consider in a immutable string we also have and we have a tle okay and mutable we have a list we have a dictionary we have a set so mainly three is a main data type is there so numeric is also one of the category we are not saying that numeric is a data type so in a numeric we have uh mainly the integer float and complex so let’s understand it all the data type is one by way this completely a six data type is there three 4 5 five and six okay let’s understand the first one is a numeric data type so numeric data type you can understand is like a numbering concept which is learned in a 10th class or e8th class that’s normal numbering concept numeric data type data type I think you aware about the real number right so real let’s start with the real number a number which is really in exist in the real life we can we can say it’s a real number it’s a very simple definition of the real number right that number can be uh start with minus infinite to any number like uh uh minus 2 you can say uh – 1.01 – 1.005 like any number which is exist in the real life and zero is also considered that and one and 1.5 any number till infinite so inside a real number we have a different different uh subset is like a whole number integer number currently I’m in a you know numbering concept I didn’t enter in the programming concept okay let’s first understand with the numbering concept and after that we’ll relate with all the topic with the programming language so that we have a real number okay so inside a real number we have also the different different numbering concept is there the first one is integer okay so integer integer is basically there is no any decimal point is there like it start from minus infinite 2 it will take a minus 2 and after that minus one okay and after that zero then 1 2 till infinite there is no any decimal point and we have also the whole number is also there natural number let me just first Define natural number natural number is basically start with 1 2 3 4 till infinite that is a positive values is defined as a natural number why it’s saying that the positive values is defined as a natural number because uh you know in in a naturally we are using the only positive things right so you can relate like this this is is not a definition okay third one is a whole number whole number which is start from 0 to infinite this is the normal numbering concept I think you learn in e8th class or seventh class okay so and those number which is which cannot be defined in a real life we are calling the complex number the simple way we can say like if you have a number is like a root of five some values is there right 2.2 3 is there I don’t remember the exact number uh 2.2 something is there right you’ll get the some values but when you’re talking about uh uh the value of minus5 root of minus5 that cannot be Define so that we are defining is like root of minus1 into root of 5 so root of minus1 we are calling the Iota in a mathematics which is defined with the I and root of 5 whatever value is there so in suppose if I’m considering 2.2 something 2.23 so 2.23 I that will be the values so that we are calling is a complex number okay complex number so when you enter in the real life def uh this is the real life numbering concept we are using using but when you’re talking about the uh programming perspective so we have a only integer float and complex okay so we have int so whatever we learn in integer that is nothing but in uh that we defining here the in we have a float like if any values minus1 min-2 sorry min-2 will be the less – 2 -1 0 1 2 like this till infinite okay so floating point that can be any decimal points so like a minus U it is also start from uh you know infinite and if you have a minus two that will be considered as an integer but if you have- 2.0 that will be considered as a flow any value which we have some decimal point we are calling the floating Point number okay so minus 1.02 so kind of that values the complex number complex number how we are defining complex number like in a real life we are writing the a + I but here we are defining the any number 5 + 7 G we are not using the I okay uh that can be any number like 5 + 7 I so any number which is defining the uh Iota concept we are calling the complex number let’s try to understand with some practical implementation okay suppose if you have any number like a five if you have any number is like uh uh 5. 86 any number which have some decimal points we are calling the float if you have uh numbers like um uh 5 + 7 G which I which I said okay so when you just take the data type so we can just type here the type A you’ll get the values as integer I and T and A type of B and you just check it that is a float type of C which is a complex to understand the very details way uh so I already created one files the data type you can find it out um on a GitHub link okay so I’ll share with this file so you’ll find it out like which one is integer float and complex and as well as uh you’ll find it the type Cur one conversion as well like if I want to convert float to integer integer to float float to concept so how can we do that we Define it here okay so hope you understand the concept of uh uh in numeric data type where mainly we are using the three data type here in float and complex let’s jump on the next data type which is a which is a string data type okay so string data type is uh uh is mostly using in a data science perspective as well because let’s let me give you one example is a chat GPT I think you guys is already aware about that chat GPT so chat GPT is a totally based on the natural language processing concept it’s little bit a high level of a data science but let me just give you the um overview why the string is very very important see the chat GPT is always needed the string Command right statements you you’re writing some statement and accordingly it will be finding the pattern and giving the result to you and if I’m talking with you so that is The Voice command the voice command first is converting in a text and after that you’ll perform some operations so wherever the text is available we are apply the string command so that is the reason string become very very important because it can be easily connected with real life because the real data uh text is also there so let’s discuss the string data type okay string so first of of all string is a immutable data type immutable data type and ordered data type so like in um interview perspective the interviewer is asking that what is a string string is immutable and ordered data type which is very very important to say that this order data type okay some data type is unordered as well so I’ll discuss that like U dictionary and set that is the unordered so here what is the mean of uh immutable immutable in the sense we can’t change anything if you define the value is like I give I take the variable a is equal to India first first of all let me discuss that how to define the string string is always defined with the single quotes like I’m writing here the end single quotes we can also Define with double quotes as well make sure that if you started with a single quotes end with a single quotes if you started with a double quotes end with a double codes and uh if you have a multi-line of statement and string is there so we can also Define that with uh triple codes one line two line three line wherever ever you end 1 2 3 so same as for uh single quotes as well 1 2 3 one line two line three line so you can increase the line two three okay so that we are defining the string and string have uh uh as I said that it’s immutable that means you can’t change the values in between why I’m saying this word because of the ordering concept so this end if I Define it here if I Define it here i n d i a so where we have a positive and negative indexes available so index is always start with a zero in a Python programming language this uh concept is not for one string everywhere in the python the value is always start with a zero so the value started here here 0 1 2 3 4 so that is the index and when you’re talking about the negative index that is always start with a minus one because there is no minus 0 right so minus one that is starting with the right hand side min-1 -2 – 3 – 4 – 5 it’s five okay so you can access the values as well so those data type have the positive and negative indexes there that we are calling the ordered data type okay so string have the positive and negative Index right so here because of the this ordering concept we have a different different operations as well so we can easily slice it so in case if I’m just printing let’s do it in a practical way okay so string I have one string which is the India okay so because of this uh ordering concept so we can also slice it as well so a square bracket to using up slice always using the square bracket as I said that the index is always start with a zero so if I’m writing the zero in between the square bracket you’ll get the Valu is I right if I’m writing the a of uh uh three a of three so let me just write here a of three so which is the small i 0 1 2 3 okay so in case if I’m writing the minus two so min-1 -2 so you’ll also get the values the same minus one uh sorry min-2 that you’ll get the same values min-2 right so the index of U the value of index 3 is I the value of index minus – 2 is also I right the same values because we have a positive and negative index as well so in case if I want to assign some values if in a of two which is a B I want to make it a capital letter can I do that capital D it will giving you the error so if it Define the particular order you can’t change it if you can change it that’s become the mutable if I change the order if I change the values in between that become IM mutable so obviously um in Python everything is possible if you want to change it it’s possible in a different way but the string is not giving you any kinds of method to change the values directly you can’t assign directly here okay that is the reason is a immutable immutable inmutable means in the sense non-changeable mutable means changeable all right okay so based on that we have a different different operation is available we have a concatenation suppose India and uh I have a um B statement which is the country country okay so the a plus b if I’m performing the operation I’ll get the Valu is India country okay India country in in the in case if you want to Define some space in between so a plus you can provide the space the plus operation is used for concatenation plus operation is used for concatenation if I’m using so India space country perform the operation like this so let’s go to discuss about uh method and function in a string uh string data type so let me just conclude what I discussed okay so I discussed this slicing I disclose the concatenation and we have also one more thing is a repetition okay we can also repeat it with star symbol slicing we are using the square bracket concatenation we are using this uh Plus and reputation we can use the star so for example I have the value is uh variable is a I want to multiply with a five then you’ll getting India India India five times so that is a reputation okay a small small thing is there to go in a very details way again you can go to the data type if you already aware about these things so you can skip or you can just make this video is a 2X or 1.x faster and just complete it and go through this uh Jupiter notebook and run this file you’ll get a better idea but don’t forget to run this uh uh jupter notebook file okay so here I already explained okay so you can just run it just shift enter shift enter run it you’ll and you’ll understand each and everything but again in case if you make any doubts if you not understand anything you can just put your question on a comment definitely I’ll reply you okay so let’s discuss about uh okay I need a space all right I need a space keep because I don’t want to remove it okay so let’s discuss about the next thing is a function and method which is very very important every data type have a different different method and function okay let me first write a method and some function so actually the method and function both are a same there is no any difference this have a very small differences there if function is always defining like a def here I’m not explaining you the details of the function whatever in build function whatever in build method is available in a string that I will discuss it here okay so why the both are a difference see method is always calling with a DOT like I have suppose a is a variable a is a variable which is the India okay so method is always using like a Dot Upper a do lower a do capitalize okay a DOT count a do index small I there is no Capital index so other uh method is also available but when you’re talking about um function so function is like a len and we are passing the values a len means length we have um uh mean we have a mix okay so these are and we have a type so actually this uh uh function is a very common for for all the data type so when you just enter in the list tole dictionary so you’ll also find it out the same type of function that will not change but the method will always change the difference between the uh function and method is that if function is always defining like this and then function name f n if I’m writing defining like this if the function is separately available we are calling function simple but if the function is available inside a class we are calling the method class class name is a okay if it’s available inside a class we are calling method so when I start the objectoriented programming I’ll go in a very details way just now you can just understand like this the method is always using with a DOT and a function we directly call it and to know that which one is a function you can directly understand like if you find it out any statement after this bracket that is a function that can be either function or method if you’re using dot method not using function okay so few method I will discuss it here and uh after that I’ll stop okay because uh no need to explain each and every method when you just run this uter notebook you can easily understand okay so as I uh Define all two variables a which is India B which is a country and I want to make it a Dot Upper so that will make it is a upper case okay it will be make as a upper case a do lower that will make it a lower case small I and uh currently the a variable is already the capitalized capitalize in the sense first letter is a capital the second letter uh remaining letter is a small one let me make one variable is equal to I’m using Python programming language okay so let me just use small I when you just use a c do capitalize okay sometimes uh when you just forget your uh you know that method spell when you make it spellings little bit wrong so it will giving you the error so the best practice is that after this variable put a dot put a tab you’ll getting a different different suggestions I’ll make a capitalize I don’t need to write everything capitalize is already there okay when I just run it you’ll get the values I’m using Python programming language so the first L make it as a capital the rest of the later will make as a small one so C do title there is one more valuable uh one more method is a title everything makees a first uh letter is a the capital of the particular word okay so again to go in a details way so you have this one string data type which is immutable and ordered so you can find out here all the different different uh method and description is also there it’s very understandable way so when you just run it shift tab shift um shift T shift enter when you just run it you can easily understand so again I’m also there in case if if you face any problem okay so these all the options are available till here okay so suppose I have a statement um Rahul got 78% marks in mathematics exam okay so this is the one statement I want to make this statement and dynamic way like uh the name which is a Rahul okay and marks I’ll make a m variable which is 78 78 which is the integer and U subject which nothing but a mathematics okay this three variables I want to make a statement in the dynamic way so making the statement Dynamic may we have a three way to define it let’s discuss the first one string formatting uh the first one is we can print here so the first one is Rahul so Rahul is a subject so I’ll make the name is a string so I’ll make percentage of s okay that percentage of s I’ll make the dynamic way uh Rahul got 78% marks so percentage of s percentage of I I for integer marks in mathematics exam which is the percentage of s s for a string and I for integer percentage of s exam okay and after that after a double quotes you have to use a percentage and in a bracket you have to pass the values 1 by one the first one is a percentage of s which is nothing but a name I’ll pass it the name is here second one is a m which is nothing but a marks third one is a subject I’ll pass the subject here the name will be passed in the percentage of s m will percentage of I which is a integer and subject is uh that mathematics so here showing the 78 so the best part of is that in case if you have some decimal uh numbers is here like let’s say for example you have a 78.6 7 um when you just run it till you’ll get the answer is let me just run it here again still you’ll get the answer is 78 the reason behind that because I pass the values is the integer right so in case if you want the proper decimal point you have to make is a float you have to make as a float so by default that floating point is giving the uh till of five decimal point yeah six decimal points so it’s on you you can easily U you know dynamically you can just change it I can pass it here only the two decimal point so 0.2 when you just pass it you’ll get the values is uh 78.6 7 in case if you’re passing the one decimal point so 67 it will be convert into seven because after six the seven values is greater than uh 0.5 that will be uh round of seven okay but here the percentage symbol is not visible so when you just pass the one percentage it will be show through the error because unsupported format uh because here the considering that if you pass the 1 percentage the meaning is you will pass some um you know the data type here as well that can be string that can be float that can be integer so avoiding this confusion we always using the double percentage so that will consider as a percentage okay so one percentage will consider as as a like you will pass some data type but actually you don’t need to pass some data type right so double percentage you can use it so here uh uh like uh s we are calling string I we are calling the integer so again in the data type already the values is available you can just make it string integer float character everything is there okay so this is the one way to defining this string formatting there is also one way is also there to defining the string formatting you will just write a print and uh whatever values is available like Rahul so he’ll make double quotes always there because of the spring uh this one curly brasses ra you will consider as a dynamic values Rahul got curly brasses percentage marks in cly bres exam okay so here the curly presses you have to pass the values here like I will pass the value is uh name I will pass the value is uh M I will pass the value is subject just before you have to write F this is also the very simple way but again if you make the statement is a very Dynamic especially in the number format so this one is also useful you can also use this one one also so both are very same you can use it sorry we have to give this space and yeah full stop so again everything you can find it out here uh you you can easily find it out here uh one more thing one more is also there uh dot format option okay so you can just use it the same thing here curly brasses got Rahul got curly brasses exam uh cly Braes marks in cly bres exam okay and after that just do format and you’ll pass the values is one by one okay so here when I just pass the value is um uh name first what will be consider and then M then subject again so okay s j c so again you will be confused that what is the difference between in that okay this option is available then why I will use this so this one also have some uh plus point is that suppose um here you have to pass the proper order otherwise the value will be swapped so but in case if you pass the different order I’ll pass m is here I pass name is here I’ll pass a subject is here itself when I just run it you’ll find it out the value is 78 got Rahul percentage it’s very weird statement right so actually the by default uh this one uh the indexing point is also there 0 one and two so when I just run it so by default the values is there but actually this uh the zero index it should be it should be here so I’ll make it zero here okay so you can see you’ll find it the two times because I also pass the zero is here as well so here I’ll make the one so you can change the order as well so all three have a different different positive points uh we can use it okay so one more topic is also there in uh string formatting so uh string formatting is done in a string there is also one more topic it’s very small topic is um skip sequence and uh raw string skip sequence and raw string let me put the heading here skip sequence and raw string okay skip sequence in the sense suppose if you are uh writing some statement and the value will not be print in the place of that uh uh that symbol it will be showing the meaningful result let’s say for example I’m writing here I um working in Python programming language okay which is uh dynamically type language okay I just want some statement after the uh High I want to print in next line I’ll use the slash n so sln is basically going to the next line right it’s not like that it will be print the slash okay and after the statement again I want to in this next line it will be in the next line I want to uh dynamically typed language have some uh space as well SLB B for backspace okay B for back I’ll make the t t for a tab okay so when you just run it you’ll get the values is because of the sln is giving the next line because of this sln is giving the again next line because of this SLT is giving the again some spaces here so that’s why it’s giving the uh uh that meaningful result not exactly is the printing the values right so this one we are calling the skep sequence so I just uh Define it here a different different type of skip sequence like slash n for next line/ t for tab SLB for back space SLR for reserved and uh Slash a for alert so different different skip sequences there sorry it’s a skip sequence okay skip sequence and what is a raw string so raw string in the sense sorry draw string in the sense if if uh you want all the statements as it is I don’t want to print the meaningful result I want as it is values so just before you have to write r that will consider everything as a raw string so the value is not displaying it here sometimes it’s very useful whenever you’re reading some particular files from local machine or in particular server okay suppose if you are reading and uh somewhere the double slash is available single slash is available so python is giving some meaningful result but you don’t want you want as it is uh path so that time we are using the r especially for uh reading the CSV file in the data science we mostly using the r to avoiding the errors okay so that string topic is finished so we covered everything we covered uh four thing here the first one we discuss about uh what is the String which is the immutable and Order data type and uh we discuss about the positive and negative indexing that can be easily slice and uh concatenate and repeating values and uh we also discuss the method function and we discuss the string formatting skip sequence and Ross string so that complete the details again if you have any confusion you can just put on a comment and uh please refer that um uh jupter notebook file your confusion will be cleared there okay so let’s discuss about the next topic which is a tle so tle is one of the smallest data type like uh uh like a number number is very small that was only uh you know uh the integer float and complex but the tle have some values but it’s not as much of uh big topic so let me just cover it in this video only okay so again the tle so first we have to clear that what is the definition the Supple is again it’s a immutable and ordered data type ordered data type okay when you’re talking about the how the tle is defining the tle is defining in a round bracket suppose I have a value is a five a 8 7.0 and high okay so that I store in the variable T so uh uh first of all this tle is a comes under the sequence sequence means is a particularly order and that collecting the data right so the five is a integer 7.0 is a float high is a string so that is a that’s why the tole is become a uh sequence which store the different different data type even inside a tle you can also store the list as well dictionary as well anything so the tle list dictionary in the set that working as a container so the container is nothing but a sequence okay so here as I said it’s the ordered data type so again have a positive and negative indexing is there okay sorry uh oh why it’s showing like this okay have a positive and negative indexing so 0 1 2 3 have a positive indexing and as well as we have a negative indexing as well -1 – 2 – 3 – 4 so like the tle we can also apply the uh slicing order like uh the T slice with uh uh two you’ll get some values obviously you’ll get the value is 7.0 right you’ll get the value is 7.0 in in case if you pass the T of three you’ll get the high but in case if you pass the minus 3 then the value will change that will be 8 right so we can also apply the concatenation here we can also apply the multiplication here so this symbol is used for concatenation and this symbol is used for repetion okay so and uh the likewise the uh string we have also the method and function are available so the best part of this uh tle is that not a best part but uh yeah uh the tle have a very less method when you’re talking about a method have very less and a function okay so method have very less just we have a count count method like T do count and T do index that’s it we don’t have other method is here so again is a tle uh again is a immutable so that means we can’t change the values in between and uh the function when you’re talking about so it will be the same as the which we discussed in the string that like U uh what is the max values what is the mean values what is the um a type okay there is also one more function is available which is a tle which will be responsible to convert any data type into tle okay okay so mean Max is there yeah and we have a len which is very very important Len which will show you how much uh data is available inside a tuple so let me just clear it in the practical way it’s very uh small data type we can see so again you have to refer the data type Jupiter notebook you’ll find it out the practice uh um notes there okay so tole I can Define it here in the round bracket I’ll make this the T1 be Define in the round bracket 47 7.9 and um uh high is here we can Define it and he we can Define it okay so let me also Define one more variable is a T2 where I can Define it 4 5 6 2 there is very small values so the T1 if you access it uh access it with the two so the value 0 1 2 which is a 7.9 you value will generate sorry it’s a T1 not a t 7.9 value will be generate but again I want a 7.9 High both the values so you will start with two you will start with two and end with high start with two and reach till three so the p have a rules that never end with last values so if you’ll write three that it will be considered as a range the 2 to three it will start with a true but not end with three okay so it will showing the value is 7.9 so you have to write here the four this rules is not for only tle it’s rule for everywhere in the python always start with the index always start with zero first thing second thing never end with that values always ending with before one because of that let me write it here always start with index zero and in case if you pass the range is uh 9 meaning is that the value will start from 0 to 8 okay so here when you just pass the two colon 4 the meaning is that prob with two and three like this so this will be applicable for everywhere in the python not for a tle only okay even the last data type which is discussed that was a string it’s also applicable for them also okay so we can also apply the concatenation T1 + T2 you’ll get the value is the complete concatenation we can also apply the uh repetition as well so if I’ll multiply with the three then you’ll get the three times that same values okay so these are the values are available and uh uh we have a different different method as well before going to that method let me just uh do the uh negative indexing and some more values try to get it suppose I want this both the values uh 6 7.9 and high from negative indexing so T1 this is the values I want to start with 6 so that I will take the value is -1 – 2 – 3 -4 so I’ll write write the minus 4 here and when you just print it you’ll get the Valu is minus uh you’ll get the values is six and when you click only colon then it will be start with a uh minus 4 till last okay but I don’t want a high so this the value is minus1 and I want to end with here so when I just write a minus 2 min-2 so you know that it never end with the last values is always always ended before one right is before one so definitely it will end here you can run it and check that so better do you have to use minus one minus one in the sense it end with min-2 this is the rule of python is that never end with last values and always start with zero if you are not defining and the values is always start with the same same if you are defined this is the way and one more thing suppose I want to make this order as a reverse how we can do that so the E1 you can make it and when you make a colon that meaning is that start with the zeroth index end with last okay and after that suppose uh okay after colon you can also increment and decrement so by default start with a zero 1 2 3 in case if I’m writing the two so it will be jump like this 0 2 4 and I just run it you’ll get the values like this but if you make it minus one okay the first place become the minus one then again it will be decrementing so it will make the reverse order okay oh sorry T1 the T1 values of this and you can make is the reverse order all right here if uh if I’m applying the method and function the P1 dot count okay count you can just count it how how many times that values is available I want to know that how many times high is available will tell you yes it’s a one time is available right so in case if you have a multiple times high is there like uh uh T2 how much is there okay so let me make a T3 is equal to T T1 + T2 T1 + T2 so this one P3 I want to perform some operation how many times four is available let’s make it p 3 dot count and make it four you’ll get the values is two okay so again the t uh when you apply the index order dot index index will tell you where is exactly the position suppose I want to know the position of 7.9 7.9 it will give you the value is sorry it’s a T3 give you the value is 2 0 1 2 but the confusing part is here confusing part is here if I want to know the position of six P3 dot index of 6 what will be the values it’s one but I want to know that what is the position of this if you’re walking in the Jupiter notebook click on it here and inside a bracket just write shift tab you’ll get the complete notification okay so it will tell you where the position are starting and where is ending so ending is a huge number and starting is a zero so always start with a zero but if I’m start traveling from the one uh sorry 0 1 2 if I’m traveling from the two so that means it will not check the previous one so here if I start a start T start is equal to two if I’m writing so that means the the two is here it will check only these part so what is the position of six in this part okay start s t take no keyword argument okay let’s remove it so you don’t need to pass the uh keyword there okay so when you just pass the two here the meaning is that it will be start from two only from here it will not check the previous one so this way we can find it out a last thing uh I didn’t uh discuss that why it’s called as a immutable because I have the D1 in case in the place of 7.9 which is the second position I want to replace with some values like U hello so you can’t do it that is not supporting in the tle so tle is mostly used for a security purpose uh the value when you’re defining in uh any any metadata or we can say any storage place we always using the round bracket so that when you start working on a python it should not be changed by mistake to assigning some values okay so now the tle topic is finished this is uh the topic is there in a tle so if you have any confusion you can put on a command we completed the three data type numeric string and tle so now let’s discuss about the next topic is a list that is the fourth data type list so list basically a a mutable data type so whatever we discussed the previous one is a tle string and numeric that was a immutable data type but this one is a mutable data type mutable and ordered data type again so mutable means changeable ordered means have a positive and negative indexing so list is always defining with this is LS is a variable defining with a square bracket that can be the any data type you can just write it like integer 5.8 is a float High okay and uh 7 five so you can Define like this so it’s a square bracket all right so have a positive and negative indexing as well because of it order so we have a 0 1 2 sorry three and four I have a NE negative indexing as well minus1 -2 – 3 -4 – 5 so when you’re talking about the operations so it have also the same operation like a tle and string so we can perform the operation like uh slicing so like LS of for the particular slice if you do it uh like one so you’ll get the answer is 5.8 so if you the slice is the multiple values um like uh 2 to 5 so you’ll get the answer is high so that will be the single quotes here High 7 and five that is the more than one values is always in the square bracket okay so we have also the uh uh this symbol plus symbol which is denoting as a concatenation concatenation okay and uh the star symbol which denoting as a repetion okay that will repeat the Valu in the many times and uh the same as um same as the tle we have also this method and function are available but because of this mutability because of the changeability we can change the values so we have so many method and functions are available so here I will discuss a few method and function and later you can just run the Jupiter notebook file you’ll understand easily so method and function our function is the same that will be Len that will be mean that will be Max that will be uh list list also the function okay and uh that will be the type okay this function very common we we we are using in uh every data type so only this one like for a list we have a list function for tle we have a tle function string we have a s Str function okay so method when you’re talking about so method is um uh we have uh like U we have a DOT count okay we have a um we have a index that that is a common it’s there for a tle and uh in string as well and we have also the other method is like append which is very famous append insert okay so many method are available so again when you just run the jupyter notebook you’ll find it out all the methods there so few method I will discuss here and I’ll discuss in some practical implementation here okay you’ll find it out in the Jupiter notebook each and everything okay as I implemented almost every method here but still if you’ll get any confusion I’m there so let me create one uh heading is a list okay so LS is a variable I’m making some values here 6 comma 3 comma 8 comma 4.7 comma uh H comma K okay so if I want to change the value is H to hello so what is the position of H which is the 0 uh 0 1 2 3 4 that is the fourth position so fourth I want to which is nothing but a h i want to make as a hello hello and later when I just check the values is LS so yes I can see the value is hello so it’s very simple we can just do it right we can just up change the values because of it’s a mutable data type we can easily change the values which is defined inside that right so here H is changed so whatever index is defining for H so in the place of H is showing the hello but you can’t do it in a tle okay so uh we can also uh slice it many things like LS of four what is the values is a hello LS of U uh 2 which is the8 from the eight I want to Define with the last values so you can see the last value is this one but the same time if I want to print till a f only five only so it’s saying that it’s LS not s saying that 8 4.7 and hello right 8 4.7 and hello it reach till four only right so it will take two it will take three it will take four it will not reach till fifth values okay so we can also perform the operation like a concatenation repetion as well I have LS2 which the list is containing the 742 and when I just perform the ls plus LS2 so you’ll get the value is is combining the all right so adding the all the values is here so concatenation we can perform we can perform the repetion as well it’s repeting the values right we can perform the functions as well here all the functions in LS I want to know that what is the length LS so you’ll get the values is six there is a six elements are available so uh inside the list tle dictionary and uh set so that values we are calling the elements right this elements are available there is a six elements and uh when I just perform the operation of minan of Ls so you’ll get the error because these all are a number but the hello and KY is a in these both are a string so string cannot be compared uh to each other right less than greater than symbol is not supported between the string and integer so what we can do it here so we can just remove it or else you can just take the any other like other variables so here when I just check that what is the minimum values in LS2 so which is the two and LS uh LS2 what is the uh maximum values what is the maximum values so you will get the values is seven so we can find it out this way but again so when I just uh competiting with the tle and list for example you have a tle I already Define I think let me just use H T1 tle I want to change the values Pi I want to make is a he uh not a he I want to make as a uh hello okay so we can directly convert this tle into the list so when I just make the list of T1 so it will make the complete list but in a list we can perform the operation right so I can store in the temporary variable temp variable I store it you can store in any variable obviously temp I store it and I just pass the value is the position of high which is a 0 1 2 3 so when I I just pass the value is three you’ll get the answer is high and when I just perform the assigning the values perform the this assignment operation hello here and check the value syst temp you’ll get the hello later again you’ll perform the operation like a tle you’ll convert your list into the tle so make the values this okay so we have this option like uh the the list we have a list function tle we have a tle function so because of that we can change the values right so lots of method is also there that we discuss the um function so method is also there for example I have a list LS I want to add some values so ls. pend we can add some values here suppose 400 I want to add it I can add it here LS the 400 is added but at the same time I want to add in the position of the two or we can say just beside the eight so you have to find it out the position where you want to add it 0 1 2 3 in the position of three I want to add it so upend is always adding in the last but when I just use the ls do insert so this is also one of the function insert so you can what what you want to add you can just take the help from Jupiter notebook shift tab it will tell you where you want to add sorry first where you want to add index is where you want to add I want to add in the position of three what you want to add I want to add a th000 more so when I just run it and check the values LS th000 is adding in the position of three okay so the 4.7 is just transfer in the one position so that means it’s a mutable right the position is changing it here but when you’re talking about the list and a when you’re talking about the tle and a string that cannot change the positions okay because that is a immutable data type insert we can perform we can perform the uh deletion operation so here uh append and insert we mostly use for adding the values if I want to perform deletion operation so that remove operation here I want to remove hello we can directly remove it here and check the values as LS so value is removed so that value is removed from the uh from the values we I just passed the values here but I want to pass the index so ls. pop is there pop is taking the index I will pass the 0 1 2 3 4 5 I’ll pass the index is five the pass the index is five then it will be removed the uh K values take the ls that is remove the key and here you can perform the main Max right there is no any string values is available you can perform it Max obviously it’s a th000 so you can perform here okay so likewise we have lots of method is available remove is there pop is there okay so other method is there you can just check it in uh data type see sorting method is there if applying the ascending order desc ascending order right we can apply the clear clear will remove the all the values there you just run it the shift tab shift Tab run it you’ll understand everything it’s very simple way so much method is there again you don’t need to remember each and everything but you should know that that option is available in a list okay you don’t need to remember because a very small small thing is there okay so in a list there is one topic is very uh famous which is the list comprehension list comprehension so this list comprehension is mostly used for optimizing the code so whatever code you can write in a three four lines because of the list comprehension you can make it to one line and it’s very fast okay so suppose I want to display the 1 to 10 number it’s is very simple example 1 to 10 number so with the help of for loop I can display it here for I in range I can pass the values is here one to uh 11 so this is the rule of Python programming language is that is always starting with that particular values and if you’re not assigning that will be considered a zero and never end with last values okay because the range of 1 to 10 1 to 11 the 10 values should be printed so another programming language why it’s not like that because their indexing start from one and here indexing start from zero so when I print I so it will showing you the 1 to 10 number okay I want to perform the operation based on that I want to perform like U make a container of the uh uh you know the cube of all the values so when I just make it Cube because when you have the particular list and perform the uh I want to store in okay like that suppose if you have the particular list I want to make it all the values as a QBE format but in that time when you just directly perform the operation like um suppose I have a LS and when I just performing a q to the power of three it will show it saying that it’s not supported so in that situation what should I do so we can directly uh you know display all the values display all the values with a for loop it’s iterating all the values is one by one what is happening here it’s printing all the values one by one right so like here LS is this LS is this I want to perform the cube operation based on that so can you do that no it’s not possible when you just apply it here Cube it will giving you the error so likewise we have the one one of the requirement is that I want to make a list of the cube of 1 to 10 so here when I just make it cube of 1 to 10 so the displaying all the values I’ll make one particular uh uh list like LS three is a blank list and every time I’ll just append it append with LS3 sorry not LS3 I I will append it uh let make it a result okay here I’m just using the for Loop but after completing up this data type I have to go in the very details of conditional statement and loop so again if you have a confusion if you if you are okay with that then you can just listen to it otherwise you can just pick the video of uh the for loop as well I have already created not already created after that you’ll get the a for Loop okay soend why it’s not working okay I have to write ls. up okay so when I just check the ls you’ll get the LS3 LS3 not LS LS3 you’ll get the values 1 8 2 7 like this so but with the help of list comprehension you can easily do it just one line of code list comprehens some syntaxes like that so so you’ll apply the for Loop for variable in sequence so before just we have to write variable okay this is the sequ this is the uh syntax of the list comprehensive so what I’ll do I will just use use the for I in range which is a uh because range is a sequence range which is the 1 to 11 and before that whatever want to print you can I I’m just printing the only I so that showing the 1 to 10 number but I want to print the cube so it will showing the cube okay so as I said that in the ls I want to make it the cube directly I can’t do it but if I apply the list comprehension there for uh B in LS3 so before when I just pass the One V you will get the as ittis values because it’s a iterate the all the values is 1 by one right it’s iterate so you have a freedom to do anything with a V so I I’m applying it here the three you’ll get the values is completely the cube of all the values right so here LS3 previously was like this uh not a LS3 let’s perform the ls you can see here previously the ls was like this let apply the cube in all the values is one by one so we with the help of list comprehension we can perform this operation and in real life in the real application we are using this one so based on the list comprehensive I’ve just given some exercise you can just try it it’s very easy I also given the solution as well here you can just try to understand and do it okay so each and everything I just apply it here you can check out and just run it one by one you’ll understand everything here okay so I also created the 2D and a 3D list right so 2D and 3D list let me just explain a little bit 2D and 3D list 2D and 3D list okay so L if you have a list like this that means it’s a one day list okay it’s a one day onedimensional only if you have LS2 is like uh a particular list is there the list inside a list so list inside a list like 4 6 8 comma in the second list we have 3 5 7 like this so that means there is a two rows there’s two rows and three columns so that means it’s a 2 cross three Matrix is there right so when you have the same kind of with a three dimensional as well like uh LS3 so this is the particular one di uh it’s a 2d list I’ll make the 2D list in the same time I will also make it this 2D list in a one particular wrapper so let me change the values like a 15 16 18 13 15 and 17 and everything I’ll make one particular rapper then it’s become a 3D list right in a 3D list that we can say that it’s a this was the two rows three columns and I apply the one more D there right which is the two so 2 cross 2 cross 3 the value will be 2 cross 2 cross 3 it will be right we can if you want to iterate it the for Loop will really help you so it like if I want to slice the values LS uh LS3 this is the values I want to change in the position of 16 okay I want to change the position of 16 first you have to find it out so which uh uh Block it’s available this is the F this is the first block this is the second block so available the second block that means 0 1 so I find it out this block and again it’s a which block it’s uh because I want to change the value is 15 right again is a which block is a zero Block it’s a one block it’s one again what is the position it’s a one I want to change the values is a I change the values when I just take the ls three obviously LS3 get the values is high so this way we are performing the list operation and we can also iterate with the for Loop like for I in LS3 so it will be iterate the one list will be iterated here one bracket will be trated here like print I you will get the values in one list one list and the second list right so again I I want to iterate it so for G in I print G so when I just display so you’ll get the value is G iteration so again I can iterate it the uh with a G as well for K in J so then you’ll get the value is a okay so you’ll get the all the values so if you have a three dimension you have to apply the three for Loop to read each and every element okay so this is the list uh 3D 3D I also completed and list comprehens I also completed all the methods and function as well please check out this Jupiter notebook your all the doubts will be clear now we reach till fifth data type which is a dictionary so dictionary is a little bit different with tle and list what is the different different is that there is no any positive and negative indexing is there in the dictionary that means dictionary is unordered data type but it’s a mutable data type if it’s a mutable let me just write it first it’s a mutable and ordered data type sorry unordered data type unordered data type okay so there is no any positive indexing for a dictionary no any positive and negative indexing so dictionary is a defining like key value pair with curly brasses key colon values okay Curly brasses close so if I want to Define any dictionary so we can Define the dictionaries like this so suppose the variable is a D in a curly bres I’m defining the value is a colon 15 comma B colon 18 comma Zed colon 19 again I told you there is no any restriction for a data type if you started with any string is here and I want to put it here is a integer you can do it there is no restriction any data type as I said in a tle uh topic itself right so likewise the tle this is also one of the container but it’s contain the data as key value paay so likewise uh couple and list so we’ll also discuss about the operations their method and function so when you’re talking about the operations so we can also slice the values but with a key because there is no any 0o 1 1 2 3 there is no any positive and negative indexing is available right so we can’t directly access it suppose if I want to access the value is a 15 so I will write D of a okay we’ll write a d of a then you’ll get the value is a 15 if I accessing the value is a d of Z so you can get the value is 19 this way we are accessing the values but here you can’t perform the operation of the concatenation and multiplication means this star symbol you can’t perform it this plus symbol you can’t perform it so I’m going to remove it this part okay so likewise the uh list and uh uh tle we have also the method and function is available so let’s talking about method and function method and function so here this is not a sequence right which have a positive negative indexing and defining in the one particular uh uh brackets so we can’t use it mean and Maxes here but we can use a length we can use a type we have also own uh function which is a d CT D this function is also available so when you’re talking about the method so also have lots of method is available here like uh we have a do keys keys like if I have a diction if I have a variable is a d so d dot oh it’s not running okay wait wait a minute just me just open it again there is some web problem okay so let me just continue with this okay so we have a keys we have the values as as well okay we have pop okay we have the uh uh Keys values and items so the lots of method is available let’s do it practically let me jump on a practical implementation this one and uh we’ll also discuss about their application as well where we can implement the dictionary in the real life okay okay yeah let me just remove it these things all right let me create one file here all right I already created let me just take it experiment yeah again you have to follow this uh J notebook which is already there in a description you can just uh access this link via GitHub and just run it you’ll find it out all the information here right but I’ll just run it few um you know method and function here yeah the same dictionary a same Jupiter notebook let me create here dictionary I’ll create one dictionary is the D1 is equal to in a curly bres suppose like uh uh R and pass the value is 19 K I’ll pass the values 8. 8.9 I’ll pass the value is e colon hello I will also pass the value is the 5 colon 19 so there is no any restriction for the data type so like you started with the here the string so the key always should be a string it’s not like that you can pass anything here this this restriction is not there in anywhere in the python all right so D1 if I want to access any values I’ll pass the Valu as a k you’ll get the values as 8.9 and D1 I want to access the hello you’ll get the value is oh what’s a what’s the problem oh sorry I just accessing the value is hello with t that that is not possible I can access the T I can access with the T and get the value as a hello right this way it can be performed okay so when I just perform some operation methods here like a D1 do Keys you’ll get the all the keys here okay so r k T5 these are keys and what is the values E1 dot uh values you will get the values here again if you uh if you already aware about that you just the run this file which is I shared with you the dictionary run this file and run this video in a 2X or 1.5x you don’t require to listen each and everything right these are very basic basic things is there and just when you run you’ll understand so I’ll just give you the complete overview here okay so suppose if I want to add some values so there is no any upend option is there right there is no any upend I want to add some values how can I add it so the D1 pass any keys I’ll passing the keys here like uh U I’m assigning the values here 1,000 so when I just run it and get the values here D1 you’ll get the U in the last values okay so like way we can also assign the values so dictionary have some um you know applications so I’ll discuss about that again I will not each I will not write each and every line code so I’m taking the help from here suppose if I’m defining the values here okay here this is the list okay so question is why I’m creating a list here why not sorry this is the tle uh why I’m creating the tle here why not a list the reason behind that tle is very much secure secure in the sense we can’t change the values so most of the time we are using the tle as a key in a dictionary okay so it’s not like that you can’t create a list you can but most of the time we are using the tle because of the security purpose okay so T1 is a tle I want to make each and everything as a dictionary so you know that the Cur if you make the curly brasses like blank curly brasses so uh for example uh D2 blank cly brasses when you check the data type that you’ll also get the data type is a dictionary dict here is showing the dick not a complete name is a dictionary all right so this D1 I want to make as a uh dictionary uh dictionary key so D2 which is is nothing but a dictionary Dot from keys there is a one method from keys I’m passing the values is Keys which is a T1 so you’ll get the values is like this name as a none because I didn’t pass anything colors is a none like this so I’ll make I’ll store this values in the D3 even you can store in the same variable as well it’s on you right so let’s assign some values so D3 I’ll D3 this I want to assign some values in place of the name so I’m assigning the value name okay here you can assign directly any name like Rohit you can assign it or else you can create the completely a list here it’s on you like inside that you can Define one key in the values you can pass n number of n number of uh uh n number of uh uh you know sequences sequences in the sense in in one sequence you can create it like a list on top you can Define the multiple values what is my target here I want to create a complete table I think you you aware about Excel you you seen Excel somewhere right at least I’m expecting this this time okay so in a table suppose I have one name I have a a phone number and I have a um marks something like this so okay so the keys is this this values is always constant this is nothing but a column name so when you’re talking about the terms of the dictionary that will be calling this part as a keys and all the values will consider as a values okay so values of the particular key so likewise I want to Define some values suppose the name is name is uh name is like RIT okay uh Manoj John and their likewise their values is available so you can Define it so in a terms of dictionary when you’re talking about let me just remove unnecessary things yeah okay I want to create the complete table in the terms of the dictionary which will be the pair of uh list and dictionary okay so I have many names available I’ll I’ll just copy paste from uh this file so this one I’m just defining here okay I’m just defining all the values so name I Define the M marks I Define the 90 subject are defining the uh ma maths and college are defining the Mumbai University okay so when I just run it so you’ll get not info obviously uh you have a D3 so d 3 D3 D3 okay when you just check the D3 you’ll get the values like this at the same time if you have a multiple values you can also Define it m I’m defining with uh the other name is John so again if you have one values you don’t need a container container or a sequence we can also say if you have one values we don’t need a container if you have multiple values we need a container which can be either which can be either list or tle I’m just making here a list okay you can make a tle it’s not a problem okay and I’m just passing the values 56 and any values so maths let me pass the English okay let’s store it and uh Mumbai University and uh okay IIT Bombay all right so when I just run it so you’ll get the values is like this so here the m and John you’ll get the same time if I want to make it this as a table this is not look like a table but there is a library which you’ll learn maybe um after U uh 8 nine videos topic is the package and modules there is inbuilt packages available is the pandas import pandas okay I’m importing the pandage which is inbuild package and already installed in a Jupiter notebook and Anaconda if you’re walking with any other libraries then you will not get it par directly you have to install it import pandas and pandas do data frame so I’ll just make it completely a frame okay frame and when I just pass the values at D3 run these values you’ll get the complete table where the name College subject and marks is considered as a keys where the other thing considered as a values so when you just enter in the data science part currently you are just learning the Python programming language when you enter in the data science so everything you are dealing with a table and the table we are reading in the data frame format then you’ll start the operations so if you start the operation if you already aware about that yes this table is nothing but a collection of the keys and values right so mes John Mumbai University iitb this is nothing but a values where is the name and college that’s considered as a keys so let me just Define is the variable DF data frame and DF when I just pass the values do Keys you’ll get it the keys because this is nothing but that data frame is also nothing but a combination of list and dictionary so when I just pass the DF do values you’ll get a values as well see everything is a values there is no any Keys okay and some other method is also uh adding here like a DF do columns which is not there in the dictionary but this is the method of data frame you’ll get the values but you can see the keys is very much similar to the uh DF do columns but if you perform this operation dictionary do column you will not get it this is the uh method of a data frame don’t apply it I I’ll just remove it here okay when you enter in the data science then you’ll understand here just try to understand that a table is a made with a dictionary and list so again I request you to run all the files you don’t need to create anything if you want to do experiment do it but at least run this file this all the values is available like uh how we can get the keys how we can get the values items how we can perform pop clear operation how can get the values how can add some values how can update the values right so this is one one line of code you just run it you’ll understand easily each and everything like here creating some particular data frame is here so likewise uh list we have also the dictionary comprehension dictionary comprehension is the same as list comprehension the only thing is that the syntax will change the reason structure of the dictionary and a list both are a different let me first remove it this I’ll write the syntax and after that finish the dictionary comprehension all right okay dictionary comprehension okay dictionary comprehension when you’re talking about uh the syntax the syntax is very very same call brasses so again we have the key values pair suppose if you apply the operation is like for each in sequence so here you have to perform the key colon values is mandatory I want to print one to 10 number okay I want to print one to 10 number but at the same time I want to show the values as well suppose if you have a list you performed like for I in range which start from one end with 11 and before you just wrote the values is I and you’ll get the one to 10 number this is I you’ll get the one to 10 number but I want the cube of this all the number with the same numers should also be defined like one colon 1 2 colon 8 3 colon 27 4 colon 64 like yes so that was a list here I’ll make the curly Braes make sure that you have to use key values pair so I colon I’m just using IQ okay I Cube you’ll get the values is like this 1 28 327 464 5 6 like this until 1,000 okay so disc dictionary comprehension is the same as list comprehension while the structure is changed the set is a mutable mutable and unorder data type it’s a unordered data type okay so unordered meaning is that there is no any positive index there is no any negative index mutable means we can change the values easily in between we can delete it we can update it we can append it we can insert anywhere right but it’s unordered the meaning is that we can’t put any index so that we can access it so defining the set we are defining like this is the curly brasses even dictionary is also defining with the curly brasses but have a key value pair and here curly brasses and with the values directly 5 8 7.9 High K like this so this is a set so there is no any uh you know the same data type concept is there in the entire python again when I said the statement the many times again I’m saying there is no any data type okay so that don’t be confused anywhere so when you’re talking about the method and operations so I think set concept you already learn in a school days set the right so whatever you learn like a union section and difference and a difference update um you know this same thing same concept is also available in the programming language as well we talking about the operation so we can iterate it with the for Loop like other programming language for Loop concept we can apply it but we can’t access with any index even in the dictionary we had key so that we can access it here we don’t have any key if you want to take a values is one by one you have to apply the for Loop okay even the for Loop you can apply in any data type so when I will not write it here okay we’ll directly jump on a method and functions okay let me just write it here method and function again there is issues okay method and function so method is basically uh let’s first discuss is the union okay and the second one we have a intersection I’ll just write a small small there is not a capital intersection we have a difference okay we have a difference here is a point okay so set if you have defined with the S so s dot s dot s dot so let me just explain you a little bit about what is a union what is a intersection and what is a difference okay so suppose I have one set S1 which Define the value is a 5 7 8 and 10 I have a different set S2 which Define the value is uh uh 3 7 uh 11 and 9 okay so when you just created the complete set let me change the color complete set so there is one set where the values are available is a five 7 8 and 10 there is one set S1 and when you’re talking about the S2 so S2 is like this okay 7 is also available it’s a 3 11 and 9 when you’re talking about uh uh the um Union when you’re talking about the union so Union will take s One Union which Define the symbol like this in S2 and in a programming language we are writing the statement and s do Union with S2 okay so it’s there is no any symbol concept is available in a set programming set data type so in a set theory in a mathematics that symbol was there so the value will be the value will be uh 5 7 even 8 is also there 10 and three and 11 okay 11 I already defined okay okay here let me just write it at 10 11 and 9 okay so this will be the union so Union is basically like this we’ll take all the values we’ll take all the values better the same way we’ll take all the values here all right okay so when I talking about uh the next concept is a uh intersection so S1 intersection S2 so it will take only the common which is the common values here so here only one values is available which is a seven so intersection will be like this this part only seven okay only seven will consider as a intersection so this part will be a intersection and you know and if you’re taking entire things that will be the union if I’m talking about the difference there is also one more concept is a difference so difference uh let me just make blue color okay so if have a value is S1 and S2 here is a 7 uh 5 10 and 8 3 11 and 9 okay if I have a value is this is the S1 and this is the s 2 and if I value is S1 difference S2 if I Define like this so from the S1 I’m removing the S2 okay so it will take the value is one Le this only this part it means only the seven will remove okay because from the S1 I’m removing the S2 so 7 will remove so you will get the values is a five 10 18 so here is the very interesting concept is there he uh if I have a toule I have a list as a container so what is the need of a set so what is the special qualities there in a set concept the special Quality quality is there the set never take a duplicate values okay so I can also write somewhere let me just write it okay can I take it the next page it’s very difficult okay all right so let me go to the Practical implementation I’ll just write on a practically itself let me just remove all those things all okay all ranks yeah all right so we are learning the last concept is a set so set is always take a unique values I can write here okay so set first of all it’s a mutable let me write here itself okay it’s a mutable and unordered data type unordered data type and the second concept is that set always take always take unique values unique values there is is no any duplication you’ll find it out in the set concept but in a tle and list you can put a duplicate values as well that is a speciality of a set concept set data type if I Define the set is like the you know curly brasses 4 6.8 and K and nine so this is the set okay it always take a unique values here is sometime confused that I’m just using the curly brasses as a set curly brasses as a dictionary as well with the key value pair but how to define the blank set and blank dictionary it’s very very confusing right so suppose I have the uh a variable temp variable TMP variable so which is the curly bres so what will be the data type of temp it will be the set or dictionary so when you just check the data type okay when you just check the data type of attempt so you will get a dictionary it’s not a set but how to define the blank set so blank set is defined like S2 is equal to set set function bracket see this function we are using to define the blank set when you check the data type here S2 you’ll get a blank set okay we still here so let me just create one more a set here S3 is equal to 4 6 uh 9 okay 1 6 okay six let me just take it one more time 6 6 6 and uh uh 15 so when I just print the value is S3 you will get one this six is one time it’s not showing the multiple time here in case if you have a list if you have a tle it will showing the multiple time but the set will take always the unique values so I have S3 I have S1 I want to perform some operation here like uh Union intersection so S 3 dot Union if I pass the value with S1 you will you will get the values with the combination of S1 and S3 but the value will be always unique you can see here the 1 15 5 6 which is a combination of uh S3 and S1 here there is no any particular order is available because of the because of uh the order is not available so you can’t access it in case if you’re passing the S3 in square bracket of four you will get a error because there is no any POS positive and negative indexing is there but you can apply the for Loop here like for uh variable V in s so if you want to iterate it you can iterate you can iterate it but you can’t access any values with a square bracket like uh list tle string and a dictionary with a key that you can’t do it here okay so again uh you can perform the U difference as well we can perform the intersection as well like S1 do intersection intersection you’ll pass the values as S3 you will get the common values here which is S4 and 9 if I perform the S1 do difference okay difference so there is the two things difference and difference update so if I pass the values S3 so whatever values there in S3 which will be uh s which whatever value is there in S3 in S1 that will be removed so here the 6 and 8 you’ll get the values you can get here S1 and S3 so S1 and S3 here you can see the S1 which is a four and 9 which is a common that’s why it’s remove the four and 9 from the S1 with S3 and now I said that there is the two values the difference and difference update the difference when you apply so the value will be as it is it will giving you the result S1 is as it is S3 is as it is but if you apply the values S1 do difference update difference update and pass the value is s uh3 you will get the update updated values in S1 okay previously the value was not updated as I said that we can add some values as well we can update some values as well we can remove some values as well right so if I am talking about S3 so I want to add some values S3 do add and pass the value is suppose 56 so you can add it okay because it’s a mutable data type if I want to remove anything as three. remove I can easily remove it like nine you can remove it if I want to uh update I already discuss there is lots of things is there intersection Union difference okay so you can perform it so again you have to run this J notebook where is the last section yes last section here you will get the two difference set and performance all the operation here the one by one you will easily understand all right so you can see you’ll find it out each and everything thing yes uh the one thing I forgot to discuss with you the mean and Max and Len the same concept we can also apply it here so mean Max you’ll find it out the minimum values you can find it out the maximum values like S 3 mean of uh what is the minimum value of S3 you get one what is the maximum values of S3 you’ll get uh S3 but again don’t forget to run that jaal notebook okay that give you the more clear idea as compared to this video right video just giving you the complete overview but the details if you want to go the jiter notebook is important for you so before going to the next topic like uh uh looping concept first you have to understand the entire data type concept from the Jupiter notebook this is the set so there is one more application one application is there in a set which is the uh set comprehension likewise the dictionary comprehension we had we had a uh list comprehension so set comprehension is also there comprehension okay set comprehension so set comprehension the syntax will be the same like the and list so whatever for we have to use for that particular variable in sequence sequence can be any range any uh other sequence like a list or tle or or list or tle mainly so here just you have to write variable and curly bres is mandatory for a set okay so let me just create it I want to print just one to uh uh uh one to 10 number one to 10 number let me just print it here for I in range I’ll pass the values of 1 comma 11 is same like a list and dictionary comprehension only the syntax is little bit Chang this because of data type is change when I just run it 1 to 10 number in case in case if you you have a list okay instead of this uh set I printed the values is instead of the I I I’m just want to print high so the high will print 10 times you can see here high is printed the 10 times but if you apply the same concept for a set you will get only the one times it will be generate 10 times but the accept only the one times go here and run it so you’ll get only one times that is the speciality of a set which is always take the unique values never take any duplicates okay the last concept of the set is that Frozen set the Frozen set is basically it’s not a new thing here it’s we can say let me just remove H we can say it’s a it’s a immutable set so whatever we we had a set concept that was a mutable so here we have immutable set immutable set but again if it because of the set it will be unordered immutable set and that is the unordered okay it’s a immutable set that I was talking about Frozen set okay that concept is a frozen set so let me just discuss it little bit and after that uh we’ll stop this video because the Frozen s concept is already there in the Jupiter notebook okay the heading is frozen set Frozen set which is nothing but immutable set and unordered okay it’s immutable set and unordered so suppose I have one particular set which is the S4 and I Define the values like this okay there is so many duplicates is also there if I print the S4 you will get the only unique values so this is the set which is a mutable but uh if I want to make S5 as a frozen set Frozen Frozen set yeah Frozen set I’ll pass the S4 and run this values so S5 is a frozen set S4 is a normal set let me also Define one more set it here so 5 6 2 1 yeah that is enough okay so can we perform the operation in between the Frozen set and set answer is yes so only thing is that it’s immutable so if I want to add anything in S5 which is a frozen set do add and pass the values is anything like uh 1,000 that will showing you the error because Frozen set has no any attribute of addition but because of this set we have we can perform the operation of like a union intersection difference this values we can easily perform so like if I want to perform the difference operation here S5 do difference you can see the common values is a five and six so S5 difference with S6 which is the set normal set which is the mutable set we can say and S5 is the immutable set when you perform the operation you will get a Frozen set values okay but but if you do it Ulta if you do it the opposite one S6 dot difference and pass the values s five then you’ll get a set because I perform the operation the difference on S6 okay S5 on S6 so S5 is nothing but a frozen set S6 is a set that’s why it’s perform like this again you can you just run it it a small thing is here you will get the values finally we completed all the data types numeric string tle list and D dictionary and set but after completing of all the data type and we we discuss in the very details way but we have a confusion sometimes which one is a mutable which one is immutable which one is ordered which one is unordered because so many things is there where we can add it where we can remove it so in this video we will focus on that at the complete mind map of all the data type so that if you’re going for interview you just have to refer this slide you can easily understand all the data type in the same time okay so let’s start it so numeric data type we have a mainly three main function uh first we’ll start start with a function so we have a int okay we have a float we have a complex this three function and string we have a St Str function tle we have a tle function list we have a list function dictionary we have a dict function set we have a set function this all the data this all the function is available for all the data type all right when you talking about how we are defining so integer we are defining like a 5 7 like this the float we are defining like 8.9 with some decimal point complex we are defining like a 7 + 8 G okay string we are defining always with the if if you start with the single quotes always end with the single quotes if you start with the double quotes end with the double quotes tle we are defining with e is equal to round bracket 5 8.9 like K anything you can Define it there is no any common data type concept is there in the entire Python programming language so list we are defining like L is equal to square braet 5 8 7 9 7.9 square bracket we are using dictionary we are using the key value pair like a d is equal to key values okay key values pair and when you talking how we are defining the values D is equal to like 5 col 8 okay 7 col 9 for a set we don’t have a space so I’ll just change the color okay the set we are defining the value is s is equal to curly bres 58 directly you can pass the values this way we are defining the all the data type okay so when you’re talking about the mutability and immutability okay mutability and immutability which one is a mutable and which one is a immutable right so the numeric data type is a immutable string data type is a immutable tle data type is a immutable list is a mutable dictionary is a mutable set is a mutable okay see it is a mutable and the next one is a ordered and unordered so let me just write here ordered and unordered okay ordered which one is ordered which one is unordered so numeric data type there is no any concept of ordered and unordered likewise the uh numeric uh for mutability as well to numeric there is no any meaning of mutab and immutability because it’s not a collection anything like string is a collection of some letters or El uh okay so if you have only one letter so at least it will be defined the index is a zero right so so string tle have a meaning is that it’s a mutable and immutable ordered and unordered so likewise in a numeric we don’t need any discussion for numeric immutable and mutable string is a ordered okay couple is a ordered list is a ordered dictionary is unordered set is unordered clear set and dictionary is unordered whereas a tle list and dictionary is a ordered all right so if you want to add anything again so dictionary uh uh sorry numeric there is no any meaning of that we can add it or we can’t add it likewise the string as well so here tle dictionary tple list tle list dictionary and set this will be considered as a container because it contains some values right so like the tole we are containing the values is a round bracket list is a square bracket dictionary is a key value pair set is also containing the values whereas where is tole let me again make it different color tole list and set it’s called as a sequence okay why it’s called as a sequence because we are directly pass the values so only dictionary we can’t as a sequence because it’s a key values pair if you just iterate the values you will get a only key if you’re not passing the dot items you’ll get only keys so that’s why we are not considering as a uh sequence but dictionary is a container so this is the way where we can remember it if that is not more important like which one is a container which one is not container because that is not a question question is that which one is mutable because giving you the information that we can’t change the values it’s a immutable if you have a mutable that we can change the values that is giving the information right so the container sequence is just tell you that we can we can just uh you know wrap up the multiple values at the same time if you’re talking about the add the values so no we can’t add any values okay I’ll pass I’ll write the no we can’t add any values there because it’s a immutable but in a list if we want to add anything so we have a multiple option is available like uh append okay we have insert okay in a dictionary there is no any direct concept is available and and and we have also the extend option is there extend okay when you’re talking about the dictionary we can’t directly add anything but like this b square bracket key and pass the values is values we can add it right there is no any direct method is avable label but we can do it and uh set yes we have uh s do add method is available this method we can add the values but in a tle we can’t add anything the last thing is the delete so there is no any meaning of uh the deletion of in numeric and string because these are not a container but if when you’re talking about the tle so tle no we can’t delete anything because of it’s immutability we can’t delete anything but in a list we have a lots of option is available we have a clear option okay let me just change the color okay we have a clear option we have a uh remove option we have a pop option okay this option is available in a list and in a dictionary we have a pop option is is available okay and uh in a set we have also the pop option we have also the remove option that is a remove and we have a discard option as well okay but the important is that yes in a list dictionary and a set we can delete anything we can add anything and uh uh in a tle we can’t delete anything we can’t add anything okay so this is the complete mind map where we can just remember it and we can perform the operation this this data type operation in any applications let’s understand the conditional statement the conditional statement there is a three keyword we are using the first one is if second one is L if third one is else okay before starting the Practical implementation first we’ll understand the flow chart of uh conditional statement in a diamond shape we are always using a condition so condition is always start with if that can be two scenario that can be true and false if the condition is true then giving the statement okay giving the statement and pro uh the block will terminate after giving the statement it will not checking any other block it directly terminate okay here I’m just writing here and but if your condition is false I want to give a one more condition uh to check that time we are using L if we are not using IF in case if you’re using if that will be the separate block L if is also the condition then it can also be the same same scenario can be true can be false if it’s true then giving the statement okay giving the statement and the same thing after giving the statement program will terminate and after the uh Al if condition I want to give one more condition then again you have to use the AL if but in case if you don’t want to give any other condition you just want to stop it you can directly top this block but we always doing this practice that uh the the last one we always using else so else is not a block else is just giving the statement in case any block is not uh you know if any if any block is not passed so here I’m just using else else is just giving the statement if any block is not satisfied then else block will run and then directly terminate after the else block you can’t write any other condition in case if you’re writing that will be considered the separate block the separate section that is not a relation of the particular block so whatever we discuss that is one block is mentioned there this is complete one block like if the one condition is satisfi then giving the statement not satisfi then giving the any other state any other condition to check that the condition is satisfied or not let’s try to understand in the Practical scenario how exactly is working and then we’ll also enter the real life scenario as well let’s say for example I have a three variable a is = 5 b is = 8 C is = 19 this three variable is there and the condition is always start with if we are writing if take a space and write it down a is greater than b okay that uh your condition after the colon it automatically taking the four space that we are calling indentation and we consider as a block if I write the statement as a print hello and when you just run it and it will be check the condition is satisfied or not so a is greater than b means 5 is greater than 8 is it true or false so obviously is a false that time is not giving any answer but if the condition is satisfied like a is really less than B that means five is really less than eight then it’s giving the answer is hello okay but here I put only one condition in case if you have a multiple condition is there if a is greater than b okay if a is greater than B that time will print normally hello and and uh when you click enter after this print statement it’s automatically the same block this is the same block but I want to write one more condition so obviously I have to go back and write one more condition which is the L if L if C is greater than b colon let’s write some statement statement is hey and if I want to one more uh uh if I want one more condition I’ll write it the L if is a is greater than C there is a three condition I mentioned there and simultaneously you can just write a many condition is here okay hello hey hi and after that we always using the ls this is the good practice in case if you’re not using it will not show you any error so likewise here it’s not showing any error so same wise here it will not show any error if you’re not using else just write down here else colon and your statement print hello uh just buy else is always execute if any block is not executed previously if any block is not executed that time is working so python is always working the top to bottom okay it always check that line number one is um um satisfied or not satisfied a is greater than b the meaning is that a is greater than b B that is false Okay C is greater than b which is true a is greater than C which is also false and else is always is a default one in case previous one is not executed that time it will run okay so here the block number two here the third one line number three is execute it when you run it it giving the answer is he but what happened is all the condition is satisfied all the condition is true like a is greater than b okay A a is less than b uh and C is greater than b and uh a is also less than C that all the condition is satisfied so what will be the answer the answer will be the first one because according to the rules here which we discussed if the first condition is satisfied is giving the statement and terminate the Block it’s not entering the next block because l l if will check if the first condition is dissatisfied right if the first condition is satisfied is giving the statement and terminate the block but here the L if is after the false of the first condition so here it giving the answer is hello one day again the last one if no any condition is satisfied that time the buy will execute which is the default one if nothing is there nothing no any condition is satisfied like uh I’ll just change it here uh greater than less than greater than so all the condition is false there is no any true condition and uh so when you just run it it giving the answer is by because nothing is satisfied here this is the way of conditional statement we are using but again do you think that we are using this kind of conditional statement in the real life answer is no we are not using this kind of conditional statement this is the way where we are learning we are starting the conditional statement to connect with the real life let’s take one example and we’ll understand it how exactly the conditional statement and other things like a loop is working the example which I selected that logging with username and password login with user name name and password okay this is the real life scenario where we’ll implement the conditional statement let’s say for example one one different example and obviously the practically we will use with the username and password login if you’re going for applying in a passport in a passport office there is a first condition you should be eligible for 18 year old okay if you are 18 year old the first condition if you you satisfied then it will be check second condition do you have a pan card do you have a AAR card do you have any other government documents it’s like that like it is like condition inside a condition right so here in the real life we always using condition inside a condition that scenario we are calling nested conditional statement the statement which we are using calling nested conditional statement nested conditional statement okay as we discussed in the last slide so where we decided that if and L if is using for a condition where is the else is giving only the statement okay else is not giving any kind of condition only the if and L if given the condition let’s understand the flow of the Ned conditional statement the flow is always start like this if you have a condition condition one okay so obviously the condition is always start with if that can be true scenario can be true can be false okay if the uh condition is false that time if you want any other condition we always using Al if okay if you Al if that can be true that can be false that we understand in the last uh slide but if the condition is true and I want to give one more condition okay that I can write here condition two I want to use one more condition what will be the keyword is it be a if or if the answer is if okay so previous slide what we had we had is like if the condition is satisfied given the statement and not satisfied that time Al if or else right so there was no any confusion Al if is always coming from the false but if I want to give one more uh condition that time which keyword we have to use the keyword which you are using it here if if the condition is coming from if the condition uh as I said that Al if and uh if I have right Al if and if I have so both are giving the condition right both are giving the condition but if the condition is coming from the true part and if the condition is coming from the false part so we are using accordingly if is coming from the true then we are using if the condition is coming from the false we are using Al if hope this one is clear so condition is always the two scenario the true and false okay if the condition is true and again if you want to give one more condition condition number three so again we have to use if but let me just stop it here if you want you can just increase it accordingly I’ll give the statement okay I give the statement and give the statement if the statement is given OB obviously the program will terminate I’ll make the termination is here end program is terminate in the end it will be check in other block if you have okay so here given the state condition is uh the statement is uh ended again if it’s a false I want to give any condition so what will be the keyword condition number three what will be the keyword the key keyword will be Al if keyword will be Al if right why the AL if because is coming from false part so if its condition can be two possibilities can be true can be false if it’s true and here here if I want to give any other condition then what will be the uh keyword condition number four what will be the keyword keyword will be if because it’s coming from the true part okay and and then let’s give the statement I I don’t have much space so I’ll just close it here okay okay and then program will terminate and after the false if the condition is a false it here don’t worry we’ll understand with the Practical scenario and that is a real life example so you can easily understand okay so giving the false if the false and if you want to give the condition L if you can use it or else I am just using here the else with statement okay else is not giving any other Condition it’s just stop the block the same time here this El if I after the El if I want to give the condition I want to give the condition let’s condition number five okay condition number five then it will be start with if not Al if why because the uh uh the condition is coming from the true part okay so it’s giving the statement after giving the statement program will terminate after the statement program is always terminate it not take any other section okay and here is a false was there here is a true was there after the false it’s on you you you can pass any else block you can otherwise you can D directly terminate the block here I am also terminating the block without giving any else part let’s make it a else part it here okay else part and terminate the block so this one looks little bit clumsy but uh it’s very easy when you start doing the practical and uh when you start doing any practice okay uh let me just summarize it what exactly the conditional statement is working with Nate conditional statement see we have a if we have a l if and we have a else okay if and L if is giving the condition these both are giving the condition and this is giving the statement is not giving any condition and this one this condition is always start in it start always using the if always if we never start with L if and if the condition is coming from the true part we are using if if the condition is coming from the false part we are using Al if very simple let’s try to do with the Practical scenario okay so to understand the Practical scenario with the Ned conditional statement again uh this is I have to write one more heading uh which is nested conditional statement nested condition okay nested condition don’t worry you’ll find it out this uh this Jupiter notebook below the link in this video okay so suppose I have one username which is very simple just like um a hurry and the password which is defined it here currently we are not connecting with any database in the future we definitely will do that I’ll continue with this this example in a very broad level hurry 1 23 it’s very this is the password is very simple hurry 123 I want to perform the operation condition if the first one I have to take a user so uh user input user input I I take the example is input please enter your username okay the same time the password uh password input PS WD I can write it here it’s just a variable input please enter your password okay the condition we can just perform it here if your user input is match with double is equal to you are comparing you match with user if it’s match with you can just writing it this currently I’m just checking that my program is performing well or not user name is correct so when I just run it it’s uh asking that will please enter your username username I’m just writing the hurry and is asking the password is hurry 1 2 3 so the username is correct that means whatever I wrote the program that is perfectly fine okay so when I can say that my uh when I can say that uh you log in it successfully if your username and a password is correct right so if your username if your username uh is match with hurry and if your password WD input is match with password okay this password and his input is matched with password that time I can say that print login successful logging successful okay all right so let’s run it again and check that so here you can say the if inside if you perform it right if you have a multiple username multiple password that time you can just perform accordingly L if can also be performed I I’ll show you so when I just run it your intro username which is the hurry password is uh hurry 123 okay so logging successful but again when I just run it there is one issues if my username is incorrect still is asking that what is your password if my username is Inc correct it don’t need to ask the password right so if I’m my password is a correct so it’s very difficult to know that which one is wrong so it’s not showing any other any information you can see here it’s not giving any other information so this is wrong we have to use else so that we can tell to the user hey your password is wrong your user is not wrong the first issues you have to solve it here is that it should not be asked the password until your username is correct okay my username is correct the time it’s ask the password right if I run it my username is incorrect it not ask the password that I perform well but if the username is incorrect I have to give the proper answer hey my username is incorrect so the line number three If it’s incorrect I have to use else block for that else I have to write there my usern name is incorrect okay my username is incorrect not my username username is incorrect that’s it username is incorrect some explanatory symbol okay username is incorrect right so if I’m writing anything any uh not proper username then it’s saying that username is incorrect but again if my username is correct like hurry and it’s asking that enter your password so if my password is incorrect that’s not giving the proper information I have to write something here for the line number five if block else print the user uh print the uh password is incorrect okay password is incorrect so that we can know that which which is my incorrect uh you know section is there if I’m writing the hurry password is incorrect the password is incorrect is mentioned there let’s run it again hurry already 1 2 three now properly loging logging successful and in the real life scenario if you have any proper software so after the logging successful you can start is any other function any other block to uh different application you can start from here right from this uh username and password login in case if you have a multiple username multiple password then what will perform so I can also perform like I have a multiple username I’ll copy it I’ll not do anything with this blog multiple username that uh another username is a kind of uh John John 123 right so here I will use because the first condition is not satisfy I want to check one more condition that will be the L if L if user input is uh if user input is match with um the previously it’s checking with the user So currently I’m checking with John that was uh hurry and that was uh Harry 123 right previously I defined a different variable but I I can write it out directly here here John if my um user input is a match with John okay the time I will ask the password again the same thing I’ll perform I’ll ask the password what is your your password if my password is also match with here I will use if not Al if go back again you can check it if your condition is coming from the two the time we have to use if right here if the condition is coming here L if if the condition is coming from the true we have to use f okay so you can use it here just give me a minute yes sorry for that let’s continue I will use the condition here if my password p a s WD input is match with is match with John 1 2 3 if match with the John 1 12 3 the time I can write the statement print um logging successful okay Lo logging successful that can that time I can also write it so here you can say I use the if inside if I use the AL if inside the if right I also use the else as well so username is incorrect like if not match with not match with John the time is giving the username is incorrect but in case if your password is incorrect and here password is incorrect I didn’t write anything let me just write else password is incorrect okay when you just run it is asking that your enter your username I’m writing the John okay it will also accept the hurry as well and here I am writing the hurry 123 so that’s saying that password is incorrect because it’s already enter in this block and is checking this kind of password okay it cannot be checked the previous one let’s run it again hurry H 1 12 3 is giving the loging successful John John 123 is logging successful it’s perfect L fine so hope you understand the scenario and when you’re talking about the future persp future perspective of this login with the username and password the simple thing is that what can be the uh future scenario the first thing is that if you have the thousand of user thousand of password then how we will maintain it so you can use the dictionary to maintain it in a temporary basis and that permanent basis you can use the database second example is that if my username and password is incorrect so the block is like down block is uh stopped directly like a password is incorrect stopped but it should be ask the password one more time right so the time we are using the loop so the next con concept which you are using which is a loop and where we’ll discuss that how the loop we can perform with the user and login pass uh this example there is two types of loop is available let me back two types of loop is available while loop and for Loop okay before going to the Practical implementation we’ll first discuss about the flow chart so the every Loop there is a condition and after that we are entering the uh block right the condition is always showing in a diamond shape and statement is a rectangle shape so here the condition is not defining with if the condition is defining with a while if you have a condition and uh condition and I’ll Define it a while okay so that can be two scenario that can be uh true that can be false here I’m writing the false uh because of the reason I I’ll show you because it will be very difficult to define the structure that’s why the false I’ll write in here can be true can be false if the condition is a false that time is also giving the statement okay the time is also giving the statement and you can also write one more condition like with while we can also write a condition with if anything you can write it but if you write the condition with a while let me write properly while if you write the condition with while then if the condition is true the giving the statement giving the statement after the giving the statement back to the loop again it’s never terminate the difference between the conditional statement and loop is that Loop is end Loop is continuous uh running whereas the conditional statement is ending okay so the loop is end when the condition become a false the one only one way to condition uh there is only one way to stop the loop if that condition become false okay this is the way our Loop is working so when you’re talking about a nested Loop so nested Loop is also the same but before going to the nested Loop let’s first understand some practical scenario the last video we discussed uh uh this example I’ll continue with the same example before going to this um you know real life example I’ll give you some small uh you know exercise suppose a is equal to 5 is is equal to 7 and B is equal to 9 is there okay and we wrote uh I just want to print 1 to 10 number not to this number with this number I want to print one to 10 number so I want to start with one okay is equal to 1 so while there is a condition while there is a condition condition condition is a should be less than r equal to 10 so one is really less than r equal to 10 a while is working kind of condition with a loop right condition with a loop and and write the statement is uh High okay so the number a is equal to 1 which is true which is giving the true section to uh true statement here and it will enter inside a loop and 1 a is always one so when you just run it here when you run it here it will be run in uh like a infinite Loop because a is always one and 1 is always less than or equal to 10 so it enter in the infinite Loop so you can see here your process is still running so it will never stop so I have to forcefully stop it here and then I’ll tell you where how the proc process will working okay I’ll make the increment I’ll make the increment here a is equal to a + 1 a is equal to a + 1 so what will be happen he starting the a is equal to 1 and also print the a as well a is equal to 1 the next time is become a equal to a + 1 so a + 1 is become a two two is assigning to the a it not ending the loop it will running again and again again and again and until the condition become a false here the condition become false like if the number become 11 which is not less than or equal to 10 then the program will stop when you run it 1 2 3 4 5 6 9 8 10 okay program will stop so you can just write down here uh program finished finished okay program finished so when this blog will end then program will finished okay and this we are using so as I said that this is the why while is working as a condition with a loop if it’s a condition so I can use the default statement like else so yes I can also use LS it here and instead of writing here I will use it here so when the condition will be running it will be run that statement and when the condition become a false the for this condition become false I can use it here okay so like this this one is working so when you’re talking about the nested Loop how how the nested Loop is working so here I will just focus on the while loop okay for Loop we’ll discuss later I’ll focus on the while loop here so nested Loop how it exactly is working I’ll just connect with the real life scenario as well let’s first understand with the uh flowchart okay let me remove yeah so I have a loop I have first condition condition with the while okay that can be true scenario can be false can be true okay if it if it’s false so it’s on you you can uh write uh statement without else with else as as well so I’m just writing here with else else statement again State else okay else is always giving the statement No any condition so the condition number one and if the condition become true I want to give a statement you can give the statement okay according to the rules it will be back and repeat it again and again and this will be end but I don’t want to uh repeat it only this block I want to add one more condition is here so what I will do I will write one more condition condition two that again it will be used with while okay and that can be two scenario like uh the previous one can be true can be false false okay if it’s a true then it will be repeat the block it will be repeat the block I’ll give the statement okay I’ll give the statement after giving the statement it will be jump it here but again just think about it if here the condition become false I give the statement the program will terminate the answer is no program will not directly terminate here when you just directly terminate if you’re writing that means it’s a false this is not like that it will program terminate if you have a loop inside a loop this one is Loop inside a loop we can say nested Loop we are working right The Heading name is listed Loop if the program uh the second Loop because it’s coming from here after giving the statement here if the block if the uh condition is a false given the statement after giving the statement it will be back it will be back it will be back to the loop if the first one is also false then it’s okay if the first one is also false then given the statement then ter end the block this is the way our nested Loop is working okay so to understand the scenario I’ll give you one example and with that example we’ll understand okay I want to print 1 12 100 number uh I want to okay I want to print a 1 to 100 number 1 to 100 number okay in the 100 number starting 1 to uh 20 I’ll print hello and 20 to 40 I will print a high and then 40 to uh 70 again I’ll print hello okay 70 to uh 72 uh 72 100 again I want to print here okay I want to print uh let me also put one more condition 70 to 90 print hey again 90 to 100 I want to print hello again you can see I want to print hello three times one time two time and three time so in between high and ha is also there so how can we perform with a nest uh you know nested Loop is here in this example let’s try to understand okay so instead of writing the loop I can write it here uh while and for but I’m working with the while okay I’m working with the while all right I want to print one to 100 number let’s print one is is equal to 1 and uh while a is less than Ral to 100 and just print the hello first okay hello and with that number a all right and uh let’s increment it is very very important otherwise it will be enter in the infinite Loop let’s run so 1 1200 it printing in the hello but my question was that in a 20 to 40 I want to print high okay and 70 to 90 again I want to print he let’s first focus on this 20 to 40 hi and again hello 20 to 40 so I will enter inside the loop again while a is greater than 20 and a is less than or equal to 40 okay less than or equal to 40 if it satisfy the time I print high and with increment a is equal to a + 1 so what will be happen so it’s printing 1 to 100 number 1 2 3 4 5 6 100 right but in between if the this block is satisfied like 21 so again 21 let’s print a as well 21 High 21 22 High 23 high like this this program will run repeatedly when the number become the 41 it back to the again Loop is this satisfied or not yes it satisfied that means the 41 is also less than or equal to 100 then again hello will print when hello will print run the block like this 21 to 40 like this okay and again hello will back because because I want to print the 40 to 70 hello again so I will not write the separate program for hello okay because previous block it already running the hello the same thing I have another condition which is for 70 to 90 he so I’ll write a while a is greater than 70 and a is less than or equal to 90 I’ll print the value is a a again you have to a is equal to a + 1 you run it so high which is start from 21 to 40 again 71 to 90 again hello this is the way our Loop is working okay this is the way our Loop is working this is the process so hope you understand let’s try to understand how can how can we Implement with our real life scenario which I promised in the last video Yeah copy just paste it here I want to incrementally running this program okay incrementally running this program so let me just remove one block let’s make hurry only okay so what happen if my username is incorrect it show knowing that username is incorrect but it should be giving the option for to pass username one more time this is not showing it here so what I can do I can apply the loop is here okay I will ask the usern name in a loop while I’ll make it true directly I’ll make it true when I just make it true yes I’ll make it through it here when I make it through so it will be uh you know in on a looping format so it will ask the question username username is hurry which is incorrectly I’m passing it here so it’s saying that username is incorrect okay when I just pass hurry again so it’s asking the password password is incorrect if I’m passing here it’s saying that password is incorrect and again is asking the username let’s pass the hurry hurry 1 123 proper password logging successful after logging successful it should not ask anything so what is a good practice of writing the code writing code is that make a small code to run it and check that where is the mistake and Sol it one by one okay so if the my loging successfully so make sure that you have to break the loop okay if here I’m forcefully breaking the loop because I’m not performing any numbers is here so that after some time the number become a false it will never be false so that’s why I’m breaking forcefully okay so again username wrong is asking the username is incorrect so hurry I will write hurry 1 2 3 so logging successfully into breaking the loop okay so here I want to perform the nested while loop because you can see when just run it hurry uh wrong use uh yeah hurry and password is wrong the time it should be ask only password but it’s asking that password is wrong and asking the username one more time it’s not make sense so what I can write it here hurry hurry 1 2 3 let me just close it I will perform the condition that uh this password uh password condition separately while true and everything I’ll put inside a loop so what will be happen if my username is correct if my username is correct it will be enter in the second Loop okay entering the second Loop and if password is wrong it’s not going back directly it will be repeating only the password part let’s run it oh sorry let’s run it my username is hurry password is wrong it’s asking the password only okay if my password is correct hurry 1 2 3 so what will be happen logging successful is a break the loop but it’s breaking this Loop only but the problem is not breaking the first Loop that’s why is asking the username you can see it’s breaking this Loop there is a two while so obviously there is will be the two break okay so after the break I have to break one more time is here okay in this condition here as well if my blogging successful I have to break two times inv Violet okay sorry here I can’t use it because uh this will be here why I think so yeah why I can’t use it because it will be the same block password is incorrect okay wait a minute I make it wrong this is for inside because it it was impacting to this else that’s why I was not able to use it so username is hurry password is incorrect is asking that you ENT enter your password only I’ll write the password is here hurry 1 2 3 it’s showing that login successfully properly Stop the Loop so I am giving you one uh task for you so you have to apply the numbering the the task is that I will explain in after two three videos okay I’ll explain after two three videos not a two three videos after the uh loop ending so the task is that apply oh not here sorry I it code hurry hurry 1 2 3 the task is very simple you have to apply the number part apply number in apply number apply count if username and password is failed in three times okay if the username and password is failed in three times so you have to stop the uh apply the count block account block if the username password is a failed in a three times so your your process should be blocked for some particular duration just imagine that if you’re applying the username and password in ATM machine it’s blocking for some particular duration like 24 hours so you here you have to block for just 20 seconds 30 second right so I’ll explain you after two three uh after completing of the for Loop so whatever flow chart is showing it here for while loop that is also applicable for for loop as well the syntax of the for Loop is a little bit different uh when you compare with the while loop so basically how exactly the for Loop is working so for Loop is working like for this is the Syntax for any variable you can write it and uh that sequence in sequence and the code whatever um block you are writing so I’m just writing here the block so you can whatever uh you know block or any statement you want to write you can so here the sequence can be anything sequence can be your range sequence can be your list sequence can be your tle sequence can be your set right anything so basically the for Loop is used for the iterating of the process if anything is available in a uh you know in any container if you want to iterate it if you want to display the one by one we are using the for so let’s try to understand the Practical implementation so yeah for Loop suppose I have a sequence sequence is uh scq limes right scq is equal to range so range is one of the function which provided the sequence from one number to another number with interval so if I’m passing the range is like 1 till 15 yeah 11 so python have a rules that it never end with last values it end always before one so if I’m I’m writing the 1 to 11 that means it’s a 1 2 3 4 5 6 7 8 9 it never goes till 11 okay so I’ll just use a for any variable I’m writing the v in sequence so when I just print that variable so it will be printing the one by one it’s printing like 1 2 3 4 till 10 okay so that sequence can be anything so simply uh the range is very famous so let me first discuss about the range and after that I’ll also discuss other sequence as well so like here I want to print 1 to 10 let me again print and then we’ll discuss the details for I in range I can be it’s one of the variable 11 print I okay so one to 10 number here if I want to print 10 to 15 it will be going like start from 10 and end with 60 then it will print a 10 to 50 okay because it’s never end with the last values so after this comma it always the value is one because always incrementing with one okay but in case if you want to increment with the two like 10 12 14 16 like this let me write the 26 okay 1 to 26 so I want to increment with y two so 10 12 it will be going like this right so this is the incremental way so if someone is saying that just print 10 to one so the process will be also the the same like for I in range 10 we will start with a 10 end with one when you just print it you will not get any values because after 10 it’s become 11 but you put the ending value is one so I’ll pass it here so it will not print anything so you have to decrement the value is a minus one so it will start from 10 and reach till min-2 not a uh it will reach to two not a one because the python is never end with the last values okay so you can’t pass any decimal point is here in increment and decrement always the integer values in case if you pass 0 1.4 will showing you the error so float object cannot be interpreted as an iner always try to understand the error statement it give the lots of information okay I’m just removing it here 10 to 1 10 to2 is printed as I said the other sequence is also acceptable here uh for examp example I have a sequence is a is equal to our statement is India India so if I’m just printing the uh this uh statement India in a for Loop for uh for V in a V is nothing but a one uh variable a just nothing but India so when I print V it will be showing the value I and d i a The separately okay because it’s it’s passing as a sequence and it open it here the same thing is applicable for any list as well so in the sense if you have a uh any list is available where five whatever values is available inside that that can be string as well okay and when you just apply the for for v in LS and print the value as uh V and it will be showing the value is the sequence order for example I want to perform the value as U um 1 to 10 number with the square up of each number like I have a list okay LS is equal to IM me just write a list which have the range of one to 11 so it will be showing like this okay this is the list but I I don’t want to list like this I want to list of the square of each values square of one is one square of two is 4 square of 3 is a 9 square of 4 is a 16 like this so let me store the value is any variable is a LS so when you directly applying the ls is a square of two it will be showing the error because that operator is not supporting so how can we do like this so that time the for Loop is really help us so we can like for each any variable each is one of the variable each in LS and when you just print each showing the values like 1 to 10 number but I want the square of each values so you can just perform because these are the one by one number the square of each values when I just run it is going to square but again the square of this values I don’t want the separately I want in the proper list like the original format so it will be showing like this the that time we can use the comprehension concept we can use the comprehension concept here I’m just using least comprehension list comprehension concept basically list comprehension is nothing but applying the loop in a list okay so whatever I I printed here I can I can just wrap up with the list how can we wrap it so the for each in LS was there so whatever you want to print you have to just write before you have to write before LS okay this is the this is the syntax of the list comprehension and whatever uh data type you want I want a list just make a square bracket it will be showing you this all the values sorry not LS that output you want to print so each will be showing like this so each is showing the all the values but if you want to apply the square it will showing you the square the syntax of the list comprehension the very simple simple uh very simple is that where where uh just uh uh sequence uh just iteration for where in sequence and before just write where that’s it this is this this is the syntax of uh the list comprehension but when you’re talking about the double comprehension the concept is also very similar just you have to perform the square uh round bracket it will be a uh tle comprehensive the comprehension concept is very famous and uh very useful in a real life scenario when you’re making any kinds of projects okay back to our topic um to understand the nested for Loop last concept is remaining in uh loop next for Loop how can be perform I selected one of the example the example is uh pattern concept I think you learn this pattern in a college test pattern okay pattern concept the pattern concept uh let’s try to understand how the pattern concept is working and after that I’ll Implement in a practical way so the pattern concept suppose I have this box okay I want to show you pattern here is a star here is a star here two star here is a three star and here is a four star okay as we know that uh our index in a python is always start with a zero so the index of the Python will be can we change the color yes we can change the color yeah so the index is always start with 0 0 1 2 3 so this index is also start with a 0 1 2 3 so the basically I want to display the pattern in the order but this pattern is made with a 3 cross 3 Matrix right so first you have to make a 3 cross 3 Matrix and then apply the logic there so let’s understand it okay how to remove okay so let’s understand it here first I’ll create 4X 3×3 pattern for each in range which is start from always zero so if you’re not passing anything to always start with a zero and I want to reach still three then I’ll write four colon Print Star okay when you print star it will be showing like this uh the one line uh like um the vertical way is printed here when you just apply the for Loop inside that for each uh better to pass rows and column wise the first one is rows right how many rows you have to print one 2 3 4 so here I’ll pass R here I pass a c for c c for column R for rows let me again explain that this is called as a rows and this is called as a column okay column 1 2 3 four row one row two Row three row four okay this is the way we are using all right so I’ll just use a row basically row and column in range pass the value is a four and again colon and just print it so when you just print there is a 4 cross 4 Matrix obviously it’s not a 3 cross 3 it’s a 4 4 cross 4 Matrix so I’ll remove uh this one this one four cross 4 Matrix because there is a four call uh four section is there python is starting from the zero that’s why uh I make it 3 cross 3 but actually it’s a 4 cross 4 okay when you just print it then you’ll getting the 16 stars but it’s not in a cube format why it’s not Cube format the reason behind that everything is a printing in the next line so in a print there is a keyword is a end keyword is available that by default is a sln if you want to know you can just shift click uh click anywhere inside this bracket and click shift tab you’ll find it out what is the default values available which is slash n when you just remove the slash n with a space okay by default is a slash and will you remove it and make it is just a space it will will be the horizontal V but I don’t want all the stars is the horizontal V I want only this all four values is the horizontal V the next all four values the horizontal V the next four next four like this so what I will do I will use the column is a horizontal way but the rows I will use as a vertical way if I’m not passing anything the automatically the end is equal to sln is there so when you just run it automatically four cross for Star will Beed so till here we understand now I want to make the pattern so make the pattern so it’s very simple how can we do that see here you can understand um yeah here you can understand the first point first point is a position of the 0 and zero so what exactly is happening the the row is taking the value is uh first one first is taking the value zero and uh then it will be enter in this this for second for Loop that will also taking the value zero right so that’s why the printing the position of the star zero the next time again going back and it’s taking the one that’s why it’s one 2 3 so I don’t want the second for loop as a four I don’t I want the dynamic based on the previous one okay I want to make a dynamic based on the previous one let me just remove okay so how can we perform it so basically so whatever rows is coming I want so after that this one this part should be only one so that it will be print only the position of zero and it will be ended and back to the for loop again okay back to the for loop again and when this row become a one so this one should be two let’s make it plus one this one should be two so that’s why the column will take only zero and one okay take you only zero and one so when I just run it we showing like this and when the row become a three so this portion become a four when this become a four when this one become a two this become a three if it become a three then it will be print one this in the position of 0 1 2 so that’s why is printing the 012 and it will be reach till four only that’s why showing the push star like this you can think about a different way of the uh opposite star so again don’t try to memorize it any stars try to understand the how the star pattern is working the reason behind that the star pattern is there in your syllabus because with the star we can easily understand how the nested for Loop is working how the nested concept is is working because the star is not only display with the for Loop we can we have other uh concept is available to display the star let’s discuss the apply the count block if the username and password is fail in three times so we already generated the code where is that yeah this one so I want to apply the block if the username and password fail in a three times So currently hurry if I’m passing hurry 1 2 3 and showing the value is logging successful what if the uh login uh your username and password is wrong more than three times so I’ll apply the count processes here count is equal to Zer and in every uh wrong username on a password it should be increment where is the username and password wrong here else the password is incorrect so I’ll just make it uh count is equal to count plus one and password is incorrect um one this attempt is remaining attempts are remaining okay so I’ll just make it here F so uh let’s do it in case if my password is wrong let me just see that uh the statement is correct or not um hurry and password is wrong then it’s showing that password is incorrect only one attempt is remaining so this is not a right way okay okay hurry 1 two 3 so what I’ll do better I’ll just fix it the uh three times if your username and password is wrong is more than three times then the process should stop for particular duration I’ll just make it minus okay then it will showing that uh it only three times is remaining only two times is remaining this kind of you’ll get only three attempts okay the same statement I’ll apply for if the username is wrong my username is wrong and I’ll make it comma uh this particular attempt is remaining okay this particular attempt is remaining all right so okay this okay so if my usern is wrong uh all right I forgot to write F this is string formatting if my usern is wrong two attempt is remaining one attempt is remaining zero attempt is remaining in the sense is the last one it should be stop it here so I have to put one more condition if the count become a zero I have to stop it what I can do it here uh so anywhere like uh the breaking the loop if my loging successful I can also write L if Al if we can write Al if the count is equal to equal to zero the time please wait for 10 second currently I’ll just write in the 10 second okay 10 second and after that process should start again all right so I’ll do the same process for uh this is for password I’ll do the same thing for username as well I do it username as well but the your process should stop for 10 second so how can we do that so there is a like library is called as a Time import time okay so you can directly write the time do slip your process will stop for particular duration so I’ll do it here time do slip for 10 second so automatically it’s a second how can we know that you can just write time. slip and bracket you can just check it what exactly is there it’s a second I click on here inside and click shift tab this option is available in the Jupiter notebook only and if you have any other ideally you can find it out other options okay let me just remove so the process will stop for 10 second and after that it will again start so it’s on you if you want to put the timing you can okay so currently it will be stopped for 10 second process will yeah only two attempts is remaining one attempt is remaining I’ll write hurry password I’ll make it wrong this is the last attempt zero attempt is remaining that means there is no any attempt this is the last one I’ll write it here uh hurry password is hurry wrong let me just write it just wait for 10 second the process is still running it’s not like that your process is totally end up it’s running for 10 second it hold for 10 second you can increase it now it’s ask asking the password again hurry I will write it and again it’s waiting for 10 second because it’s already been uh uh already been you know um is a kind of uh uh already your count was Zero that that’s why it’s waiting for 10 second but it should not be it should not be after 10 second it give the three times option right but here I’m passing the wrong password still is waiting for 10 second so that one glitch is there there I have to just change it uh it should be make it zero again uh it should make it uh three again all right so I use it hurry 1 2 3 and let’s make it yes sleep for 10 second and after 10 second after 10 second Make It Count is equal to is equal to 3 all right Make It Count is equal to is equal to three and it’s here uh where is wait for 10 second and the same thing we have to apply for password as well so this is for username I think yeah this is the username I think so we have to do for oh sorry not here it already there just count is equal to is equal to 3 not is equal to is equal to is equal to is equal to is a compar comparing it’s assigning the values so let’s wait for yeah one attempt 0 attempt there is no any attempt is remaining I’ll pass the hurry I’ll pass the wrong password it’s wait for 10 second if the 10 second will end up then again it should be Q next three attempts okay so let’s see yeah two attempt is remaining one attempt is remaining hurry 1 2 3 so this way we can perform the operation with a Time basis okay so you can also apply the different different operation this is from the totally scratch in a real life we just adding some front end otherwise the back end we are applying the same process this is the good way to learn our programming language all the concept try to always connect with the real life so function is nothing but a block of organized code where we can reuse your code again and again use for performing single related actions so we’ll also discuss in a practical manner so let me first show you how the function we are writing in Python programming language so we are first defining is a def def keyword we are using to define the function now after that function name like I’m writing the hello you can write anything any function name and then parameter we are defining like parameter 1 parameter 2 parameter 1 parameter 2 right and important to you have to make the uh colon after that it will taking a four Space 1 2 3 4 automatically taking the four space when you click enter and you can write your uh function body okay whatever C code you want to perform you can just write it but function will run when you call it so here when you just calling hello when you’re just calling the function and if you define the two parameters so you have to pass two arguments okay so suppose I pass the five and six that is the arguments so the five will store in the parameter one and the six will store in the parameter two okay sometime you confuse that which one is a parameter which one is the uh arguments so this is not a much complicated thing right so let me just remove it I also Define the same like here I Define the function with function name there is a three main parameter and after that when you just writing the function name the argument one will we passed to the parameter one so parameter we are defining arguments we are passing so hope this one is clear right so argument two will pass to the parameter two three will pass to the parameter three so in the function there are so many uh types are available not so many four main types are there so the very first one is a predefined function and predefined which is system is already given the function we are just using it right mean Max int print whatever you you already use it that is a predefined function you just just call and pass the values you’ll get the answer okay I’ll give you one small trick to Def to identify which one is a function see if you have a statement and after that this bracket is there that you call as a function okay so mean is a function Max is a function print is a function after that is bracket should be there because that function is a calling all right so we can also make the function which is we are calling user defined function that means we are defining the function the third one is anonymous function we’ll discuss in um practical manner a function without name so here you can see the uh you can see the def and function name so we can create a function without name but this have a different purpose first we’ll discuss the purpose and after that we’ll show you how we can make the anonymous function the last one is a recursion function that things we’ll also discuss let’s jump on the Practical Implement implementation how we can uh uh function can perform in practical way suppose I have a very small program a is equal to 5 b is equal to uh 4 and C is equal to a + b and uh I’m just printing and just print C and you’ll get the answer is 9 5 + 4 is equal to 9 but here if you want to uh just addition of different numbers for example I want to add 15 and uh 28 so every time you have to change this like 15 here and uh uh 23 so this is very simple program just imagine that if you have very complication fun any um equation is there like like I need annotation yeah okay uh like um y = x² + 2x this is the function uh this is the one uh mathematical function this is not a programming function okay I want to create this program like if Y is equal to x² + 2 into X okay this is the function and uh I Define the x is equal to uh 15 and when you just print it okay and uh pass the value is y and you’ll get the answer is 255 and in case if you change the values is 25 you’ll get accordingly this answer but imagine that this function I want to use somewhere else this mathematical function don’t be complic don’t be uh confused I I’m talking about this is the mathematics function and which function we are talking about here which is a programming function okay here I write a mathematical function programming function I didn’t started so suppose this mathematical function I want to reuse any other places to make a different applications uh so it will be very complicated to to to call it or else you can just copy paste and write the code again so this is not a right solution so what I can do I can make one block and call this block again and again right so I have a different uh equations instead of saying the function I’ll say the equations that will be better okay uh Z is equal to y + 2 y + 28 this this is the one of the equation is there so what what I’ll do I’ll just write here Z is equal to uh and different places I want to use it y + 28 so I’ll get the answer z I’ll get the answer here 709 uh 703 so here when I just change the value is like two you’ll get the answer is eight the next time value is change accordingly but I have to use this uh program again and again so better to better to uh you know I have to run it then you number will change so better I can make a block and call that block again and again so let’s make a block is a depth EF and function name is a equation equation okay as I told you bracket is very very important parameter it’s on you if you want to Define you can otherwise you can leave it and uh like equation is the equation is y equal x squ plus 2X you required X as a input so I’ll just pass it here parameters now your block is ready I’ll just print it y okay I’ll just print it Y and I just run it you’ll not get any answer function have a rules without calling the function function will never execute okay so here I can see this is defining the function defining the function okay I want to call it so what I’ll do I have to define the values X is equal to some some something or else you can directly uh pass the values equation I’ll pass the value is five so you’ll get the answer accordingly so this one we are calling the function this section calling the function okay this SE is calling the function in case if you change the value is like uh 25 you’ll get the answer accordingly right this is the way our function is running when you’re talking about how the block is executing what is the processes behind that so process is running like this it will check the line number one okay and then go to the line number uh sorry line number one is just uh comment so obviously it will start from line number two which is a comment right comment will not execute it will just run not giving you any any answer so first we’ll check the line number two and after that directly jump on the line number six if the function is defined there it will never enter inside right and uh after line number six it’s calling to the function then again back to the line number so now you are calling so that’s why it giving you okay yeah that’s why is giving you uh it it will be uh giving the line number two again okay and then it enter the line number three like this and then line number four as well so this is the way our function is working right it’s not like that top to bottom approach so yes python is working the top to bottom approach but if the function is there it will first checking that where the function is calling and after that entering the inside you can understand one of uh uh I’ll give you one one more example the use case of uh this function let me first remove it okay suppose you are making the calculator is a simple example you making one calculator addition subtraction multiplication and division there is a four different different function you define it but at a time you are using this subtraction so other things will not execute because you define inside a block if you define inside a block so this one this one this one you can save your memory you can save your time because the other program will not execute only the sub program subtraction will execute so imag that if you have a big project and in a project at a time everything is not running so part part wise the values are running right which one is required you can just call it but you have to Define you can’t remove it and you can’t write the code again and again that is the reason function is very very important so in a function there is so many topics is there which I have to discuss here so very first topic is a return statement okay written statement other next topic which is uh we can say um so user Define which we already did equation is a user defined function and uh um uh we can say uh system defined function a predefined function we already used it like in float print these are a user uh these are system defined like a print I’m using here as a function which is system defined the two type is done and the third type which is anonymous function function and the fourth one which is a recursion function the fourth one which is a recursion function okay recursion function there is a these topics we have to discuss let’s discuss the about a return statements let me just remove it okay so return statement uh I’ll take one example like hope you remember about math there is a um library is called as a math and if I want to know the square root of some particular values like math.sqrt I’m just giving you the use case why written statement is important and what kind of problem what kind of problem is solving by the written statements see if you running any any any if you’re learning any topic first try to find it out why you are learning what kind of problem is solving this topic so like sqr I want to know the square root of 25 you’ll get the answer answer easily which is a 25 and I can store it somewhere I’m storing in the variable R and uh print this statement as a um s root of 5 is R very simple statement is there uh square root of 25 is 5 very simple statement okay I want to create like this because here the sqr sqrt is a kind of method so method and a function both are the same okay here is little bit confusing like method and function both are the same or different so method and function both are the same let me just Define it method and function so you can say method when when we Define a function inside the class we are calling method okay so here we here I created the equation which is not inside a class class I am talking about object oriented class and object which is this one is not inside a class so we are not calling equation as a method we are calling function only so here why I’m calling square root of his a method because math is work like a class uh math is a work like object which class is defined somewhere okay with the object I’m calling method so method we are defining as a function don’t be confused method is a defining as a function but only difference is that it’s inside a class so if I I have a value is like a I have a value is like a def um ABC dep ABC I Define it okay and inside you write a body so this one ABC is a function but if you define like a class class name class name is suppose U uh temp okay class name is a temp and you define it and inside that there very uh important uh parameter you always right is a self so now here the ABC become a method why is a method because you are calling like a t is equal to Temp okay you created the object here and the T dot ABC you can use it this ABC with the help of object which is a t that is is the reason I was saying sqrt is a method so now currently you’re not aware about a object oriented in a python so you just consider that method and function both are the same as a defining purpose only difference is that that method is inside a class so currently we are not inside a class so we’ll call as a function okay okay so I want to make uh the program like this okay suppose I created the function which is the Squire root okay let me change the name the same like I want to create it X as a parameter and I’ll make it it it’s a square root so um answer is equal to x to the power of x to the power of 1x 2 anything which is the power of 1 by two which is nothing but a square root okay let me again clear it like a square root of 5 which is nothing but 5 to the power of 1 by 2 or we can say 5 to the power of 0.5 the same thing and you can write it here just ANS okay when I just call this function as square root and pass the values is 25 you’ll get the answer is 5.0 which is a correct answer but can I write like this can I store it in R variable yes we can store it can I write like this print um square root of 25 is um R can I make like this you’ll getting the answer is 5.0 here but here I’m getting the value is none let’s try let’s understand it here here we print it the print meaning is that the the actual work of the print is nothing but displaying the values that’s it it’s not doing any other thing it’s just display the values so when you just um uh you know call this function here is square root 25 when you just pass it here you’ll get the answer is ANS is get the answer is five and here just display it’s not doing any other thing it’s not store any values so what I want the square root square root should store some values so that it can be defined it here so we can solve this problem via written statement see the word saying everything return meaning is that returning the value to the function so inste of writing the print I will say return so I’ll return this value to the square root so then you’ll get the values as it is like this okay so return return basically can be used any other function this function when you just calling it this function when you call it I can store it somewhere else so that we can reuse it hope you understand the return statement concept okay let’s jump on Anonymous function let’s jump on Anonymous function a function without name is called as an anonymous function what is a mean Anonymous function that we are defining we are defining anonimous function with Lambda keyword with Lambda keyword okay Lambda keyword what is the um you know syntax of that let first discussed okay we are writing the Lambda Lambda and we’re passing the arguments like uh a sorry a comma B and then you uh doing some operations let’s understand it here so syntax is not much important but you should know that how we are writing so just we have to write Lambda what operation you want to perform I want to perform the operation of um a cube of any numbers yeah we can say U addition of XY Z so I have to Define it X comma y comma Z colon colon what operation you want to perform I want to perform is the 2 into x + y + z that equation I want to perform when you just run it we’ll find it out the function is created okay function is created how can we um uh you know call it this function right function is created it’s saying that function you can um defining the function without any name here there is no any name but if you want to call it you have to store somewhere I’ll store in the result variable I’m directly storing it there and with that variable I can call it result is equal to um result is equal sorry result when you just run it it will saying that a function you have to pass some parameters I’ll pass the parameter 5 comma 7 comma and 3 I’ll get the answer is 20 because this one is taking as a argument these are the parameters and these are the operations I perform it the question is if we already have a diff param diff parameterized function is available in um in this topic then why we required this Lambda why we required answer is here let’s understand the example where we can use it this kind of function um suppose you want to create one function which is very small and you want to call it again and again why you required the separate function if you function is very small you can just Define it here call it the same time okay how can we use it let’s define one variable which store many values okay yeah this values I want to uh take only the um you know even numbers so many method is there there is one a famous function in build function is there which is the filter function I can directly use it filter function okay filter function so when you just uh put your cursor in between and type shift tab you’ll find it out suggestions so first you have to define the function and what you want to iterate it I want to iterate a and function you have to Define it okay let’s define the function name is a uh even this is the function name even and a I want to pass it so even you have to Define it right even let me Define separately def even and I’ll pass as a any parameters because whatever Val U value you have the whatever list you have iteratively one by one it will be pass and giving the answer so if x is a modulo of 2 is equal to equal to Z that means it’s a even number and should be written written as a x okay when I just run it oh so compressed so I’ll just use the list and I’ll get the answer I’ll got only a even number from this section so there is a 13 and 21 is a odd number but here I got only even number with the use of filter function but you can see here this function is very small so you define separately and it took a three line more space and obviously the calling from the different function from the different places obviously is a memory consuming so what I can do I can use the Lambda keyword so I can use the same thing filter I’ll pass the values here Lambda X and then condition I’ll apply it X modul of 2 is equal to equal to 0 and what you want to pass I want to pass a just pass it a that’s it and make it list and you’ll get the answer is yes same thing so here I defined with the five line of code here I Define the one line of so both are doing the same thing only difference is that with the help of Lambda keyword I can reduce my number of cod so that I can save my memory and space because this is your learning phase start now you are just learning but when you go in the project perspective so we have to take care about the optimization as well your project should not be take much time your project should not be take much memory so Lambda is one of the good solution so one thing the definitely you are uh in your mind uh in case if your uh number of code in a function which very big right like uh the function is very complicated here is just three line if you have a five line six line that is okay if you function if your function itself have almost 20 to 50 line so in that time should we use the Lambda keyword the answer is no so Lambda keyboard is using if your function is very small and you are it iteratively calling it the time we are using you don’t need to Define it separately you in that function itself in that predefined function itself you can use the Lambda a function call itself is calling a recursion function let me also write it here a function call itself calling recursion function let’s do it in a practical way suppose I have a function uh function name is U um process okay and inside the process this normal print statement is there hello world all right so when you just call it this process function process then as expected answer is a Hello World here the process is working like this your function um work like this line number one then four again line number one two after line number two in case if I’m calling the same function again same function again the function name is process same function again so what will be happen so it will be call the function again one line number one line number two and three again one 2 3 again 1 2 3 1 2 3 1 2 3 it will be like a loop but actually it’s not a loop it’s a recursion recursion have a limit what is the limit let’s discuss it first so here you can see uh the process is stopped now means there is some limit to stop when you scroll down you’ll find it out the maximum recurs and depth ex exceeded while calling the python object so there is a limit so limit you can also find it out with the CIS module Sy CIS means system CIS do get recursion limit get recursion limit get recursion limit you’ll find it out how much limit this recursion have so every system every system in the sense uh if you’re working on a Jupiter notebook and if you working on a normal python if you’re working on a py charm if your environment is a different then recurs limit can be the different but you you can use this command to find it out the recursion limit I can also increase and decrease the recursion limit so increase the recursion limit is very simple just you have to pass set recursion limit and I’m passing it here 8,000 okay 8,000 and later when I just check that what is this recursion limit it will showing the 8,000 but the question is how can we decrease it suppose this H world is showing 3,000 times I want to check one the five times or six times so that means I’m decreasing the rec person so there is um one beautiful feature is there written statement with the help of written statement we can perform the recursion process suppose I have a number is n and uh here I pass the value is a five and every time when you call this process when you call this function I’ll make it n minus one at the same time I can also print that n as well so that I can track it how much value is there so when I just run it you can see here the 5 4 3 2 1 and and it’s going till down there is there is a limit is a 3,000 so it will be going down and run it again and again right so what I can do hit here so when you scroll down down down down it’s a 7,000 it’s going to more than 7,000 the reason behind that I increase the limit which is the 8,000 right I increase the limit that’s why it’s going till here after uh 7,000 7,000 something and is going this statement is maximum recursion depth exced while calling the python object my target is that I want to stop in after five steps so I can use it here the condition if my n become a zero that time I will return return just um uh recursion done okay the statement is is a recursion done that’s it so because you know that after the return statement any statement is written there it will never accept okay so when I just run it it will going till uh 1 only what exact what is the meaning is that it’s not acceptable after the return statement like I think I already discussed but again I’ll tell you in the short way the dev hello there is a function and if my number number is a = to 4 and B is = 8 and return is equal to a + and before return let me just use the print print A+ B and when you just call it hello you’ll get the answer is 12 and after the print statement uh my statement is there um um hello world okay this normal statement hello world after 12 is showing that hello world but in case if you use the written statement for a plus b return statement for a plus b hello world where hello world will never display the reason behind that because after the print after the written statement whatever things is there will never be execute okay if I’m writing the normal ABCD any thing so it will be never execute so that is the uh functionality of the return statement we will use this functionality in a recursion function to stop the recursion so here the recursion is STO because when the number become a zero when a number become a zero and at that time it return the recursion done and when the line number three is executed after that whatever you wrote it will never execute that is the reason it’s not going in the next one but here the question is why the recursion done is not showing right why the recursion done is not showing the reason behind that it’s a return if it’s a return so you have to display it okay uh I have to uh I think process I have to also return yeah process app to also return that time uh whatever is returning the values it will also display so that that’s why the recursion done is also showing it here one um uh famous example is there uh uh for a recursion function uh which is mostly um you know interviewer is asking this kind of question what is the factorial number okay let me just explain what is the factorial number so factorial number you can understand like this uh it’s a application of application of recursion function okay so with the with the help of recursion function we will use it so instead of write this the factorial number with the recursion function okay recursion function so we’ll use the um recursion function uh yeah I need a pen so hope you know about a factorial number I’ll give you a short way so suppose I have a factorial number of five factorial number of 5 is equal to 5 into 4 into 3 into 2 into 1 it is going till one only it’s not more than that the answer will be 120 okay 54 20 22 3 60 602 120 but we can also write like this the 5 factorial is equal to 5 into 4 factorial till 1 till one it’s not going Beyond one it not accepting the zero because if you multiply with the zero you’ll get the answer is entire zero and uh if you have a six factorial that is a five uh 6 into can I remove okay 6 into 5 factorial if you have a 7 factorial 7 into 6 factorial so we can also do like this because the 5 5 into 4 factorial the meaning is that 5 into 4 factorial is 4 into 3 into 2 into 1 so we will use this kind of uh application uh to understand the factorial number like I’ll create a function Factor name is a fact fact only okay and I need a number I’ll Define the number is n colon I’ll return the value as the N into means N means exact number the four uh yeah if if if you take the example of five factorial then 5 into factorial of four fact of 4 which is the n minus one right if I pass the values is six the 6 into factorial of five if you pass the value of 7 7 into factorial of uh 6 but again so when I just call it here the fact which is value is a five I’m expecting the number is 120 the problem is here when you just run it you calling this function again and again again and again there is no any limit to stop it so that’s why it’s not defining anything it’s not showing any values the reason I’m not printing anything I’m not displaying anything every time is returning the values so I want to put the limit so that I can get the exact number so how can you define the limit so limit we can Define like this if number become so again you can you can see here it’s maximum recursion depth X exceeded because it’s not showing the number it’s not showing any values the reason I return the statement not to print so if number become a one for that time I will return one if I return return one if you multiply with one then will stop it’s not going any other things so when I just run it get the answer is 12 okay so you can take as a input uh uh okay in put okay I and PT okay anything you can take the variable input enter the number for factorial vectorial okay so I can Define it and that should be the integer that should be the integer here I’ll pass I and PT I n PT so when I just run it it’s asking that what enter the number for factorial I’m passing the eight is here I get the factorial is the 4320 so this way we can understand the recursion function so package and module this topic is playing the very important role for uh all the uh Frameworks and advanced level up Python Programming because uh whenever uh you enter any kinds of uh any framework work any any technology like a web development or data science so many libraries so many modules are there so here we will learn that how modules and package we can make it we can build it like uh from Custom based we’ll try to make the modules and packages so first one is a module module is nothing but uh any python file which have a py extension is called as a module so you have so many python file you create but sometime we creating the Jupiter notebook file that Jupiter notebook extension is i p y and B so that is not a module so python file should be in the py extension that will consider as a module and the module can consist of function classes variable anything because that is the file inside a file so many things we can write it we can write a function we can write a class we can write a variables anything we can write it there and what is the uh package package is nothing but one uh directory we can say where consist of the multiple modules but there is one special file is called as init so that name is init it should be available there that we are calling packages so for example I have a file which is the uh a which is the file name is a. py B do py c. py so these are all a modules but make sure that there is one more file should be underscore uncore init uncore uncore py if this one is also present and it’s available in the particular folder uh suppose the folder name is okay yeah suppose the folder name is a uh for example folder name is main so main is nothing but a package which consist of the multiple modules so let’s understand in the practical way I’ll create the multiple modules and I also explain you how we can create the packages as well like this there is a package I can also create the multiple packages as well for example like this example here so open change close these are a modules even in it is also the modules that is consist of the one folder which is called as a image Right image so image is a package the likewise the image there is also one more package it’s called as sound we can also say the package but the problem is I here I mentioned that the sub packages because you can also create the init file and make the one more folder which is the game so can you say this this one is a package this one is a package also become a package but the problem is here the main folder other folder inside that folder two folder is also available we can say it’s a package uh it’s a sub package okay so in case if you calling this one is a package that’s not wrong why I’m calling here the sub packages because it’s consist up the one more packages that’s the only reason okay someone is also calling this one is a library someone is also calling this one is a library so library is nothing but is a collection of the packages so if I clarify this what exactly it meaning so module is nothing but a consist of the multiple function and classes whereas the package is the collection of the modules whereas the library is a collection of packages or packages we can also say that it’s a collection of sub packages let’s do it practical implementation of package module and library in uh uh you know in a coding way so you can open your any ideally I’m just opening the visual studio visual studio and open one particular location where you want to walk it this package module and Library concept okay I’m just opening one folder uh yeah this is the location here nothing is available okay okay I think I selected the files I have to select the folder yeah exercise now it’s done I already selected here all right let me close it unnecessary files yeah I’ll I’ll create one file python file so file name is calling. py okay so in this file I’ll try to call any other modules let me first create any modules here even the calling file is also called as a module but the variable file is not a module because the extension of calling is a py where is the extension of variable is i p y and B so that is a jupyter notebook file both are a different so only calling is a module let me create one more file which is the load module yeah we can say load file I’ll create some function def info and uh some statement here print this is load module okay simple because variable uh sorry uh module is nothing but a collection of of any function any variable any classes anything you can write anything here this is the function I can also Define one variable here a is equ Al to 55 and uh let me also Define one more function def add and pass some uh parameters r n comma M okay and uh R is equal to result is equal to n + m and I will return return R okay so there is two function with one variable let me just write it first here two different function and one variable okay so I want to call it this function with different file so calling is a file both load and calling is available in the same location I want to call the load module so how to call any module we are using the import keyword import load so when you just use the import load let’s see what will happen you can run the file here so hope you have completed the configuration if you not then uh you can just refer uh my video for uh installation of vs code in case if you’re facing any issues you can also uh you know text on a chat all right let me just remove the unnecessary things so nothing is printed here because I didn’t print anything let me also print just normal statement print um hey that’s it hey so when I just call this this function uh this um you know this load module when I just call it here you’ll get the values is here only here but I want to call the info function I want to call the add function so if you if you want to call the ADD and info function so load do info you have to write it so when I just write the load. info you’ll get the answer accordingly so first is a he because I import it and uh in load module the statement was already there here and inside the function info the statement was this is the load module so that’s why it’s sprinted I want to call the a variable as well because I Define one variable which is the 55 a as a variable and 55 is a value so load. a you can also call it but uh that value you want to print it previously the info function is printed something here is just Define the values so I can also print it and see what exactly the values so I’m expecting that the value should be 55 so yes value is a 55 we can also call it that variable as well we can also call the function with the parameter to passing the arguments so load do add and pass the uh arguments because two parameters defined it here n and M I’m passing the parameters three uh passing the argument as three and 8 so I’m expecting the answer should be 11 so yes okay so here is not printing any answer the reason behind that I return the values I can store somewhere I’m storing the ens wer answer and that answer if I want to print it print answer so you’ll get the answer accordingly that is the 11 so hope you understand the concept of module and when you go into the next topic which is a package that is a collection of module so when I just create one uh folder inside that I’ll create a multiple python file and uh one init file as well then it’s become a package so let’s create it I’ll follow this structure load I created here so let me create other two files which is play and pause and I’ll put inside the sound folder that’s become a package okay let me create one more file which is the play. py I’ll create one function name which is the info let’s create an info so that you can remember it everywhere I’ll write the function which is the info it’s not compulsory that you have to pass the same function everywhere just for remember purpose I’m just writing here print this is but the statement I’ll make it different this is play module okay and let me also create one more file uh pause. py def info I’ll make it print this is um pause module okay all right so this is the files I’ll create one folder for them the folder is sound I’ll create it the folder name is sound sound I’ll pass all the modules play load play and pause inside that function inside that folder folder name is sound but here the sound is not a package because I didn’t Define one a file which is the init so in it is nothing but a Constructor so what is a Constructor so Constructor is whatever statement you write inside the Constructor it will automatically call you don’t need to call that function even the Constructor concept will also come in objectoriented programming that time I’ll discuss very details way but here you can just understand I’ll create a Constructor the file name is init.py that I don’t need to call it it would automatically called okay so inside that I’ll create a file which is theore uncore netore dopy so let me just write it all the statement to everywhere first uh let me just write it okay so so first in a Constructor let me write something so the statement is this is um sound package simple this is sound package and in a load I already defined so many functions pause let me just Define a def info the state m is this is okay pause module that’s it and play is already there is a play module so now I can say the package is considered as a uh so sorry sound is a considered as a package so now I want to call the info function which is available in a sound package because the sound is a completely a package let me also delete it here because it’s already available inside okay play uh load play and pause so yeah so sound is a package so let me make as a comment all right okay so if I want to call the info function which is available in the sound so you have to first call the sound okay you have to call the sound so when you just call the sound so let’s see what will happen so answer is showing that this is sound package so how it’s happened because I didn’t call anything I just import the sound but this Constructor is automatically called which is the in it so inside the init the statement is this is the sound package so that is the reason the first statement is this is sound package okay so again that info function is available in a pause module for example let’s let’s take it a pause module I want to call the info function which is there in the pause module so I have to go inside pause okay pause so you can pass as a reference as the uh a you can Define any variable so later a do info so when you just call a do info which is nothing but a sound. pa.info so here you’ll get answer which is this is a pause module there is also one way uh another way to uh call any function from sound import pause because the previously you are entered the sound and then enter the pause so here from the sound you enter only a pause so this one is a better way to call any modules any function okay so I’ll just directly pass it here pause doino that’s it you’ll get the same answer so in a real life whenever you importing any uh any packages any libraries like pandas numai anything so sometime we are using the from sometime using directly import so now you understand why I’m using a from why I’m using the import directly okay so now here the sound is consider uh working as a package so I can make sound as a sub package as well so you can create one more folder which is the image let me create it and later I’ll show the hierarchy as well so by the way this underscore Pi cache it’s just generating the cach that what function you called it so here you can see I called the pause I called the init so that is the reason it’s generated so previously you can also see what I called I called the pause and in it so that packages are generating here is also the package I call the load so that is the cpython so you don’t need to care about that it automatically generating so let me also create one more folder which name is image okay that folder name image image so inside that image I’ll create a three different file which is the open change and close with in it let’s create it from here here it will be quite faster first I have to create the Constructor okay and it then I’ll also create the uh open. py then I also create change. py then also create I think close is there open change and close py okay three files I generated here so sound uh sound is a package now here image is also considered as a package because I created The Constructor I put inside multiple module as well so I’ll put this packages this image and sound I’ll try to make it as a sub package with game as a main package okay so I didn’t write any function there but the same thing you can also follow for image as well so game here consider as a main package if I’ll pass the image inside a game let me just drag and drop control C cut I’ll pass inside image okay I’ll replace it the same thing and make sure that if you have the image and sound as a package if you want to make game as a uh library or a main package you have to create one more file which is the init then it will be considered as a package or Library underscore init.py make sure that double underscore in the both side so now game game is a library image and sound is package or we can say game is a package image and sound as a sub packages so you can say anything let’s back to our calling function yeah yeah calling modules where we are calling the different different uh uh functions so if I’m writing the same statement from sound import pause so do you think that it will be work absolutely not the reason behind that because previously the sound is a aable sound folder is available in the same location where the calling function was available yeah calling uh file was available so when I just run it here it will showing that the no module name sound reason previously sound was the same location now sound is available in the game location but if you’re using the game Dot Game dot sound because it’s available inside a game so it will work right it will work so let me also write something in uh in it of game currently game Constructor don’t have any kind of statement that is the reason is not printed here let me just write some statement in a game Constructor in init.py so the statement is this is game Library okay game library now so when I just call this again function calling function so the statement is also here this is game library because it’s available inside uh um inside a game library that this Constructor in Constructor is there in the game library that is the reason is printing here now uh this game library is available in the same location where this calling Fun calling file is available imagine that if the game libraryies is available in the different location if you want to call it again so it’s showing the error right so in that situation we have to find it out one a global place where I can put my library and I can access anywhere in my laptop so let me just change the place of the game Library So currently is here I’ll just copy cut not a copy directly cut it here and let me just put it outside because here the calling file there is no any game Library so when you just run it it will showing the error no module name game so how exactly this working because uh you know whenever you importing any inbuilt library that is pandas numai mat plotti anything in that situation uh this library is available in the global location so that we can access it so let’s take the example of fondas and how exactly is working So currently yeah so currently uh I have a many libraries so n pandas M plotly let me just open first the command prompt command prompt here okay so I am using the Anaconda prompt so I’ll just open the Anaconda prompt here so I already have a pandas but still I’ll just write a pip install pandas okay okay so it will showing the statement is that uh the pandas is already installed and it’s also showing the statement um you know the location where exactly the install C user your um you know PC name and anakonda 3 lip and side packages so the same thing here there is one um library is in build Library which is a CIS CIS is a system so let me just open the python here directly sorry here anywhere you can open it I can write it here okay so import CIS system sis. paath so it will showing you the path where exactly all the libraries and all the python packages are available so this is showing the complete list let me just open it one by one for each in. paath 1 2 3 4 print each Okay so that will showing the one by one so you can go to any location so main location is this one lib lib is Library let me copy it and open your uh Windows Explorer File Explorer and paste it there in the URL see user your PC name Anaconda 3 and lip so it showing the location here I want to see that where exactly the pandas is available you can see it here the pandas is available C user PC name anakonda 3 lip and site packages so here definitely site packages one folder is available you can just search it site packages yeah site packages and you can also search the where exactly the pandas pandas yes here is the pandas so you can find it out other libraries like a matplot li numai numai yes you can see the numai and matplot Le if you searching you’ll also find it out somewhere M plot lab okay so exactly if you are importing the pandas numai mat plot Li that all the code is coming from in this location if you just checking the pandas so inside a pandas sometime we are using a pandas do data frame so where exactly the data Frame data frame is a code so go to the pandas you’ll find it out somewhere go to the pandas and uh here is the API here you can find it out like so many things is available you can easily find it out there right so in the core I think uh data frame is available yeah you can see the reshape is available uh interchange is available indexes is available group by we are using D types we are using see inside that the lots of code is available so we are just using that particular code right so with the help and here here pandas is nothing but a library so inside a pandas so many packs of packages and packages is there with in it you can see with in it when you go to the inside of core you’ll also find it out in it somewhere okay in it in it is there see here is the init is there now so these packages libraries you can find it out where exactly is available with the help of CIS uh packages CIS Library so now the my target is that keep uh the game library is available in the local location I want to change it I don’t want in that uh you know local location so that if I’m access and we change the location so it will be showing that no module name a game so what we can do I can put this game folder in any of this location any of this location lib side packages anything I’ll directly put the lib let me go there yeah so Li so I’ll directly pass it here hope the game yeah it’s not available I’ll just put paste it here game paste it here so in your system anywhere in in in a system when you just run it it will not get any kinds of error okay still showing the error I think I have to refresh it kind of uh okay uh you can just access it uh let me just run it again it should not be it should be accessible okay let me just write it here import game okay it’s so okay let me just pass it in the side packages here is not working then I’ll just pass in the side packages side packages a lips or lips yeah okay let me just directly paste it here team okay go inside a lip and game okay let me just run it again here import G yeah this is the game Library so you can access it there is uh and the current location is my RT and my RT is the PC location and here I’m trying to access the game it’s accessible so here is not accessing why there is some some issues there is some issues let me just try to use it import game this normal import game so hope it should be available so I don’t know why it’s showing this error okay so there is some issues so better I can go in the particular location uh let me exit it so where exactly I’m working I can also search it here uh the location is the location is uh D recurrent learning python exercise okay I can just go there D CD recurrent learning Python and exercise okay so in this location I’m trying to just access the game libraries is it accessible or not so I’m just uh I think there is some issues in uh you know in in versions so I think I’m just using a different version here and different version there so that is the that is the problem because I just copy the path from a command prompt here so let me just import it here it will definitely work yeah here is working so if I’m just accessing game from game import sound dot play Sorry dot here I can’t use it uh but here I can definitely use it do sound import play okay so this is the sound packages that is also working here the play play do info yeah this is the play module is perfectly working fine here so if you put your libraries inside U uh the global location so you can access anywhere in your PC so p is working as a package manager which is responsible to install any kinds of packages or libraries so if you’re using the python more than uh 3.4 version so that means PP is already there you have to just use it so if you want to install a package like pandas so you can write it you can write it like pip install pandas that’s it so you have to write it pip install whatever libraries if you want to install just write it down so pip uh will install that particular libraries in global location in your system so there is one more topic is a name attribute I think you saw this name attribute in a Python programming language is many places so let’s understand it how we can use this name attribute so suppose if you have vs code okay if you have a vs code and uh yeah and I have one file which is a um load file load. py so the variable is 55 and DEP is equal to info and uh pass the statement is this is this is uh load module okay and one more function is available def add and pass to parameter a comma B simple and just um you know perform some operation result is equal to a + b and later return the values return the result okay now it’s done but I want if if I if my target is to create the complete a module which will be the load module but I want to test it that whatever function I wrote it that is perfectly fine or not okay so here uh I just want to um you know test it this add function is properly running or not so what I’ll do I’ll just call the function 5 comma 8 and when I run it so hopefully we will not get any answer because I return the values but when I just print the statement like uh print the statement directly so we will get the answer is 1 so which um I was expecting 13 now the answer is also 13 everything is perfect but here I just want to call the load module let me just call it import load okay and when you just import load let’s see what will happen so import load I just load the I just uh you know load the load module that name is the same I just imported the load module but here I was not expecting that answer should be the 13 because I didn’t call the add function here I didn’t call the add function let me just call the add function uh print load do add I’ll pass the values is 5 comma 12 so I’m expecting the answer is 17 so here I got the 17 but the same time I also got the answer is 13 as well which is wrong not wrong but uh I have to see that where exactly this 13 so 13 is basically I just printed here in the load module just for experimental purpose so if you doing the experiment so don’t direct don’t directly write it the experimental uh print statement so what will happen ke um if you write anything and import it somewhere so definitely that uh statement will uh call it so I can use it name attribute if underscore uncore name underscore uncore is equal to is equal to mean what is the meaning of main so main is nothing but main is nothing but the own file okay main is nothing but the own file so when I just run it here definitely you will get the answer is 13 okay I here you’ll get the answer is 13 why the 13 because I just passed the values is five and 8 so here I pass the condition if my name attribute is a main main is same file that time it will be called this function add but so what will happen when you just importing this file import load that time your name attribute is not a mean your name attribute is become a load okay your name attribute is become a load so how you can you can see that uh so here here when I just print it you will not get the answer is 13 you’ll get the answer is only 17 so let me just verify it ke uh that that time the name attribute is a main and uh uh when you just call the uh when you just import the load module that time is become the file name so print uncore uncore name okay I’m just writing here name attribute what is exactly the name attribute here so definitely here I didn’t pass any kinds of condition so that if you just use it in any other module in a calling Fun calling file so this one will definitely print so let me first print it here so when I just print it so here you’ll get the answer is the name attribute which is a mean all right the name attribute which is a main here I got the answer is mean but at the same time when I just calling here and uh run it so definitely this line will execute line number 10 will execute and when I just call it you will get the answer is load and what was the condition the condition was that the name underscore uncore name is equal toore main that means in the within a file it will be called but if you import it somewhere that will not call because the name attribute become the file name okay that condition I didn’t pass it here so hope you understand the entire uh package and module concept if you face any issues anywhere if you just importing something package Library anything so you can uh you know put the comment below we’ll definitely I I’ll solve your problem exception handling is a unexpected event is exactly an unexpected event which occurs the execution which occurs during the execution of the program that disturb the normal flow of the instruction so there is a lots of keyword is available to handle this kind of exception so the keyword is a try except else and finally so there is a four main keyword to handle the exception so let’s say for example uh this is the real life example how exception is occurred suppose if you’re running the car and car is suddenly stopped that can be any unexpected event maybe your engine failure maybe the petrol is finished can be anything but suppose if the petrol is finished the fuel indicator is giving the answer you’re giving the uh instruction that yes your petrol is finished find it out some nearby petrol pump so the fuel indicator is not solving the problem but is giving the instruction that this is the exact instruction you can handle via petrol so this is one of the example so let’s try to understand in the practical way like any unexpected event is occur to how we can handle it so open the Jupiter notebook I’ll just create a new file to better exception handling oh that file is not available yes the file is not there let me just create it exception handling exception handling okay suppose I have a very simple program a is equal to uh yeah a is equal to I’ll take a input okay as a integer enter the first number just normal program I’m just writing it later I’ll just create some issues and try to solve this B is equal to ENT andp put enter the second number okay and R is equal to a + b simple not a plus b a divided by B and I will print it R just normal answer yeah we can say I can also write it the proper statement answer is okay so asking the first uh first number that is the four I’m just passing it here second number is a three answer is 1.333 okay so it’s very normal program so you’re not expecting that you’ll not get uh you not get any kinds of error but let me run it program and 5 divide by 0 so that time it’s unexpected event is occurred so I was not expecting that I’ll get error right because it ask the question enter the first number I pass a five enter the second number I pass a zero zero is also the integer but I got the answer is zero division error so different different error is exist we’ll discuss in uh you know in pptq how many types of error is there but here the error is occurred so how can I handle it because 5/ by 0 that invalid it’s kind of invalid so if you using uh the calculator any calculator your mobile calculator you can also check it 5 / by 0 Let’s see what will be the answer the answer is showing that Infinity so if you check the 5 ID by 0 in your mobile maybe you’ll get a different answer maybe it will showing the invalid all right so different different statement is showing so instead of showing that red color error if I’m just showing the infinity that will be better so that is handle the error it’s not solving the error right so here uh so 5id by 0 the value is not exist so I will try to handle it if I’ll face this kind of issues how we can handle it so I’ll just use a try try means I’ll just normally try the normal flow of the program so normal flow of the program I’ll right okay so in case any exception occurred except except exception accept exception uh the time I can I can write it here print Infinity okay I can I can write it anything so if I pass 6 IDE 0 you’ll get the answer is infinity whatever you write it here you’ll get the answer accordingly so it’s not solve the error because 6 IDE by 0 the number is not exist but I’m just handle this kind of error if this kind of error is exist how can we handle it so in case the error is like here is saying that enter the first number by mistake I pass the value is uh T which is the string and here you’ll get a different error but instead of showing the error is showing the infinity that is like not sensible right so different different types of error is exist so here the common standard exception is available which is the zero division error which I just discussed name error it occur when the N name is not found and indentation error like if you conditional statement of for you are using the time is occurred and input output error is there eoff error is there so kind of some common standard error is available and uh we can handle it with their own name instead of writing The Only Exception so exception is just we can see the main class so where the different difference of classes is available zero division name error and indentation so let’s understand it in a deeper way in Practical implementation so here I use the try I use the accept there is a five keyword let me also write it here four keyword four main keyword try except try except and uh finally and what else yeah else else so these are the four main keyword is available in exception handling so try and accept we already used uh let me go first deeper here because the statement was that if I’m passing a t the still is getting the answer is infinity so in that situation how to handle it let me copy paste there in that situation instead of passing the exception I will pass it the uh exact error so in case if I uh face the issues okay you know so if I’m just pass it here okay T so I’ll get a value error so here I’m not getting the answer so because uh you know here I directly use the exception so when I just run it here separately here pass the R so it will you will get a value error so you can copy and paste instead of passing the exception I will just pass the value error so it will handle the one value error so I’ll write it here please enter any numeric number okay please enter any numeric number number when I just run it here and if someone is passing the any uh statement like T so it’s throwing the statement please enter any numeric number because I passed the any statement right so uh but uh if you’ll get any um zero division error then 5/ by 0 then it will showing the zero division error so again you can Define it zero division error separately okay accept zero division error so if you’ll face any kinds of um you know zero division issues so it will showing the answer is please enter any nonzero values okay so this one is perfect but here is very common question ke uh in the starting phase how you know that what kind of error will occurred because it’s a unexpected event right so in unexpected event how can we find it out the solution is that so whatever you know value error I know a zero division error I know so I can write it but your save side you can also Define it here except exception if zero division will not catch zero uh value error will not catch then exception will definitely catch because it’s a main class and inside that other classes available like a zero Division and value error so so here I’ll just write it down this normal statement invalid okay in case if value error zero division is not captured then exception will definitely captured so one thing is also here uh let me just pass okay you’ll get this kind of answer so one thing you can uh Define it here ke let me just copy the first one okay we can also pass the references as well so here instead of passing the infinity I’ll pass the invalid okay so invalid so if if someone is passing the W any U string values in an integer so definitely it will not convert it so it’s showing the invalid I can also pass the references as e and at the same time I can also Define it e so you’ll get the uh answer is T if I pass so you will get the answer is invalid even let me just Define it here uh colon so that it will be separate okay if someone is passing so it’s showing that invalid literal for integer with a Bas 10 so that means you have to pass any best 10 number but if I’m just passing any zero division issues okay so it’s showing that the invalid and uh the E is representing that division by zero so that error is also we can check it with passing the references um here is not compulsory to pass e you can pass any variable there okay try and accept we understood uh how we can use the uh else and finally block so let me also use it here okay all right so if you’re using U you know the accept after accept we can also use the else block try accept or else else okay so here I’m just writing the normal statement is um uh uh program finished program yeah program done just normal statement so what will happen here the uh program completely done yeah successfully completed successfully program successfully done because when I’m just passing any statement like 2 divide by 6 uh definitely we’ll get the answer is 0.333 and program successfully done but in case if I’ll get any kinds of error any unexpected event is occurred like w if I pass it so it’s showing that invalid and that time the program is not successfully done okay so we can apply the looping concept here uh like the program is running it again and again until we are not done so like if I’m just pass it here the while loop while true so it will be running again again and again but when the program is done that time it will be break so the else is also playing the important role in some situation uh where if everything is if not getting any kinds of error so that time else we can use it so here when I just pass W it will get the error at the same time it’s showing that invalid okay um it’s showing the invalid and again when I just pass the first number properly the two divide by 0 so it also giving the invalid division by zero but when I just pass the proper number so it’s showing that program successfully done and uh the while block is finished this way is working and finally block is kind of uh it doesn’t matter exception is there or exception is not there the finally block is definitely called okay so else is kind of if you not have any exception that time it will be run but the finally block no matter what is happening in the program but finally block will definitely execute so I will choose this one this program because it looks good because zero division is separately and value error is separately okay yeah so finally is Shing that um U like kind of um if I’m making any any any games okay if I’m making any small games so in that situation uh try accept is working very well and finally is playing the very important role create a very small game to generate a random number and we have to guess it so where I will Implement all the keywords of exception handling like a try accept else finally I will use it everything let me first create one random number so we can import import random and uh random do Rand range so we can provide the range from where to where you want to generate the random number I want to generate 1 to 100 so it will generate the random number in between so whenever you run it you’ll getting always different different random number so uh random number we can say just I I’ll I’ll pass it num that’s it okay so my target is that when I just uh when I just pass passing the input if the random number is match then it will showing the statement is that okay I guess the number but if it’s not match then it’s less than and greater than it will giveing the answer so user I will take it as a integer input please guess the number okay please guess the number and if the user that uh you know the guessing the number is greater than num then what I have to say number is greater than than uh guessing number you know your number is a greater than guessing number your number is greater than guessing number yeah random number whatever you can write anything random number okay so and L if we can also apply it if user is less than num the time I can write it here your number is less than random number okay random number okay all right so when I just run it it will asking the question is that please guess the number I’m guessing the number is a five it will saying that your number is less than random number right so that means whatever number I have to guess it the next time make sure that it should be more than five but when I just when you just run it here again so your random number will generate again right so we don’t know previously maybe the random number was uh 25 but now the random number is two so make sure that your random number should not generate multiple times okay again your random number is um less than your your number is less than random number so I will just apply the true uh while loop I’ll I’ll apply it and make sure that it will be running the multiple times while I’ll make it true okay I will make it true so it will asking the question that please guess the number and here the random number will be the static it will not generate every time but your while should be the uh you know your your while loop should be stopped when the number is match with your user is match with user is match with number so what I have to do I have to uh directly write it here um we can we can directly write it the if condition everywhere it’s very simple program you can modify it according to you if user is equal to equal to num the time I have to write it here uh okay we can write it yeah you you got the number you got the random number okay that’s it when the number is match so let me run it again please give guess the number the number I’m guessing that seven saying that your number is less than random number okay uh so that means I have to guess it more than 7 I’m guessing the 50 again is saying that your number is less than random number that means is more than 50 I’m guessing the 80 saying that your number is less than random number I’m guessing the 90 your number is greater than RDA number that means this number exactly in between the 80 and 90 right I’m just guessing the 85 so your number is greater than the random number that means it’s the 80 to 85 I’m guessing the 82 your number is less than that that means 83 can be or 84 only two only two option is there 82 or 83 or 84 is less than that that means the answer is 84 yeah you got the random number I got the random number but again it’s not stopped because I didn’t break it I have to break it here okay I have to break it here let me uh let me just terminate the program because I didn’t use the break condition here break keyword here let me just use it break when you got the number so in this small game what we can what we can uh you know add new things or new features the first thing is that in case if I’m running it and someone is passing the T I got the error so in error we can’t afford it like any kinds of error right so what we can do we can directly uh apply try okay we can apply try in everywhere and accept block because exception handling is very common for any kinds of program so whenever you building any applications so we don’t know what kind of exception will come we can’t show the red color error we have to tell them yes it it’s kind of invalid you have to write it uh you know new things uh the proper statement proper number so whatever is mentioned there in a program I’m just writing there the exception okay and just normal statement is invalid invalid right let me also put the colon here because this not looks good it’s like it’s mixing here so everywhere let me put colon colon colon okay great so try we use it except we use it and uh so if you pass it t that means it not make sense like when I just run it it passing the T so it’s invalid right uh so if you got the number exactly the random number so I want to know that how many attempts I did so that things like if I pass T that means by mistake I just pass the T it’s invalid that should not be countable so what I can do it here let me just break it uh what I can do it here the else I can use it if not exception the time I have to just Define one count here the count is equal to zero so whenever your program is run your try is run so that time the count is increased count is equal to count + one okay every time you count is increased and uh when you got the exact number uh when you got ex here I have to do it because if suppose in the first attempt you got the number so you’ll get the answer is yeah I you got the number but uh what is the attempt so attempt will be the one because zero attempt is not possible right so uh yeah you got the number after count this uh string formatting I’m just use it here so I got it like after how many attempts I got the number okay so this number should increase here let me just run it when I just pass the number is uh 50 okay your number is less than random number that means it should be higher I’m passing the 70 less than that then let me pass the 80 is less than pass the 90 is greater than okay so maybe the number is quite similar no it cannot be is it greater than that uh okay I have to go back lesson number 82 number is lesser 83 is the final answer so yeah you got the random number after seven attempt okay so I have to just make it you know here else I use it except I use it try I use it I want to use the finally block so what finally block does so finally block is basically uh your exception is occurred not occurred it doesn’t matter but the finally block will execute is a kind of if if you um if you open any files exception is occurred or not occurred make sure that the file the program is finished the file should be closed because the next time file will open so here is a game so it kind of every steps there is some checkpoints so I can just write it here just normal checkpoint that means one person will do second person will do the kind of I can make it just checkpoint like one person is finished so the checkpoint will occur doesn’t matter the exception is occurred or not right if the triy block will run finally will run accept will run finally will run else will run finally will so let me just run it when I guessing the number I’m guessing the number is a 50 one checkpoint is done right so it will Shing that yes the first one and second one is totally the separate so guess the second number it’s less than that I can make it 90 greater than 80 less than oh it’s kind of the random number is generating the inbit 85 let me just run it okay yeah you got the random number after four attempt right so hope you understand here where we can use the try in case if you have any kinds of issues you can see here suppose if you run it the program and uh you P guess the number less than that but by mistake you pass the number is uh some string so it will showing that invalid the checkpoint will still run but it will not increase the count this will will considered as attempt because it comes under the else where is this exception which is comes here will not consider as attempt so the next time when I just suppose if you got guess the number so this part will not be considered this part will not be considered hope you understand let me just finish this game okay less than that that means it’s more than that 90 okay it’s kind of every time time is generating the number is in between uh okay five attempt you can see here one attempt okay two attempt three attempt four attempt and here the five attempt this invalid is not considered here hope you understand this try except else and finally block last topic of exception handling is uh nested exception handling nested exception handling okay let me just use the same program which I discussed in the last to last session the same thing I will just use it here all right so here the normal program is like division of two number if the number when someone is passing that any string instead of any number then it’s showing the error and that time is handled by value error but in case if denominator someone is passing the zero so that time the any value cannot be divided by zero so that time the values is passing as a please enter any non-zero values so what I can do I can make it as a Ned exception handling as well because the last one I just make it um exception invalid in case both the um in standard exception Handler is not ex uh you know considered that time the exception will considered I can also make it let me just remove it this one here it’s not required I can also make it the separately the tri block everything I’ll just put inside a tri block and then I can apply it here the exception except exception so it’s become a nested exception handling like try inside a try you are just using likewise the nested for Loop nested conditional statement nested condition is means if inside a if nested Loop is Loop inside a loop nested exception handling is try we can say exception inside exception here I also use the same thing here so in case if this kind of exception is not handled that time the main exception class will accept yeah considered me just write it here the error okay so let me just pass it here suppose any value error if I’m passing so that time please enter any uh numeric values so this part is handled and I just run it 5 / by 0 that time this value is handled but in case if you passing any those kind of values which is not acceptable in value error and zero division error that time this exception will considered likewise if I’m not passing anything that is also so the value error how I explain you this one okay suppose if I’m just removing this part only zero division error is um you know available inside a try inside a try and I just pass it t here so that time is showing the values is one error because zero division error is not considered the value error exception so this entire block is become the error so which is handled by this exception class so hope you understand this exception inside exception sometimes like if you have a bigger program like any application if you are making it this Ned exception handling is really required so before going to the file handling let’s understand that how many types of files is which is available in our computer Industries so many format is there to handle the uh data with first one is it txt and uh PDF we have PDF we have CSV we have do Json we have XEL we have do pickle we have okay so these are a format which is available so this format to store the data so data can be anything so data can be stored in the different different format so if I’m storing one data which is like uh uh the college Rel College data where the student marks is there student subject is there student name gender age everything is available I’m storing the data so we can decide the particular format so if I decided the format is a csb so that csb is considered as a file CSV file right so at the end we are generating one file that can be any file like txt PD fcsb anything so these files we can perform some different different operations so what is operation Operation can be I want to open the files I want to close the file I want to delete the file okay I want to delete the file I want to you know update some file I want to newly write some file so these are operations so I created one complete Jupiter notebook so where you don’t need to re you don’t need to listen the entire video you can also refer that Jupiter notebook you’ll understand easily how the file handling is working so here the first one I just mentioned there first we’ll start with the tech uh text file so how we can write it update it read it everything okay to deal with this kind of operations we required some functions so these are a few important function is available the first one is open and close so if you want to perform any kind of operations so first you have to open some file okay and after that you can perform some operations and then make sure that you have to close that file as well so this this function is also very important so here I didn’t write the description what is the mean of read read is just reading the file read line means line by line reading the file okay write is writing the files right line space one by one writing the files but see and tell is something different so that is the reason I mentioned the description as well seek means defining the exact position and uh tell is find the position which is tells us ke where exactly the uh cursor is available don’t worry we’ll discuss in the practical way so one thing is also required which is a mode okay the mode mode is nothing but ke like what operation you want to perform I want to perform writing operation read operation appending op operation rri Operation sorry yeah rri operation or write in binary operation so here is available so I have one file which um my txt txt my text.txt I am try to write something okay so let me just do it one by one so first I will just create one files I don’t have any files there go back here you can see I I don’t have any kinds of txt file okay I don’t have any txt file so I will just create it one files so here this is the first operation open it will just open the particular file make sure that your mode should be w w means writing the files and then line by line I’m just writing the file this is my first program this is my second program I’m writing there so make sure that you have to close it otherwise it will be impact to the another files if you opening in a new section so yes I close it that means file is properly written sometimes we are not closing the files so what happened ke if you write the program uh if you apply the uh writing some uh you know lines in a text but you forget to close it so that time the file exactly not writing in the text file okay so now file is a properly written so we can also check that ke properly written or not my txt my text.txt so yes file is a properly written there so this is the first way to write the files we have to separately open it and then uh write something and then close it so one more option is also available which is a with open we have to use a with open it and if you using the withth open you don’t need to close it the reason because you’re writing entire section inside the block if you’re coming out the block that means file is already closed so this is also one of the good practice so if you’re using the with open that time you don’t need to close anything okay so I’ll also do it like let me just use it my text. TX my text one.txt let me just create uh new files it will be better so that you can easily compare it let me run it here you can also check it my text one txt so yes this is my first program this is my second program that is properly written here okay so yes this way we can write something but if you already written something I want to update it like I want to add some values which is the line number third line number four so first make sure that you have to open that file mode is very very important so here I just use a w mode meaning is that I’m writing something a is I’m appending something okay when I just use the uh third line and fourth line and if you close it and after that you can see you will find it out ke third line and fourth line is also available but in case if you’re just passing the W instead of a so what will be happen your previous statement will delete it and third and fourth will create so don’t apply the w every time w means writing means if you already exit it will be overwrite again so if you want to just up uh update something so you have to write a so I just use the my txt do my text.txt okay then I’ll check my text.txt yes this is the third line this is the fourth line actually directly starting where the um you know the cursor ended previously it’s ended here that’s why it started here and I use the slash n so that’s why it’s showing the slash in next time so now we we understand the read read line WR right line everything uh okay read uh right we we did that so if I want to use the reading okay so make sure that I should have some files okay uh so python. txt I create I have one files is a big file so you can also find it out files on um GitHub okay before going to the python. txt let’s also read something okay you can also read the my my text.txt as well let me show you how we can read it so with Way open you can also use it with open I’m just opening the file which name is my txt do my text.txt my my text.txt and mode is equal to it’s r r for reading okay and then uh uh we have to define the Define the you know as a variable as F3 I’m just defining it okay F uh F50 I’m just defining maybe it will be impact the next one because 3 four I just use it there so I’m just use the F50 F50 dot read line and then read line that’s it so it will be uh store somewhere let me store in the where one okay so we can also check that is the first line which will be printed where one so this is my first program so whatever I write it I can also read it as well but this is very small line of program so uh I can’t explain you you know much here so that’s why I I created I have one files which is the python. txt yeah this one python. txt this is the Big File okay so let’s let’s understand it how we can read it line by line and uh some particular uh specific location if I want to select it I want to read it then how we can do that for example I want to read only the python support modules python support modules and packages which encourage program modularity like this L this line I want to read it how we can read that kind of line uh you know to skipping other things and directly read this one so first of all you have to read first of all you have to open that file if you’re using the read meaning is that it will read entire things and I’m just closing it here and I just use the print I use the print the reason I want to display everything so now everything is a display but in case I want to display a few things only right so here I store let me store in the variable T why I’m storing variable T because I want to perform some operation there okay uh because everything is available in the string format you can also check the data type so what is the type of T which is the string right so like I want to know that how many times pythons is available in the entire book yeah we can say entire text okay so let me just check it so it’s available at the two times so what is the position of that that uh that pythons the first position which is the 2002 so what is the second position of the pythons so you can directly write here 12 23 means the next position so actually why I’m writing here the 213 because it will be start from 213th position so what will be the next so 66th position have a pythons okay so there is a two places pythons is available you can easily find it out here string with string operation okay so here we have a a method is a seek method seek method is exactly we can just Define the positions from where you want to start it like I I I decided that I want to start some particular position which is the python is interpreted objectoriented high level programming language suppose I want to start from there so how we can start it like we our cursor is always starting from here but I want to start here so seek will Define the position in a python yeah we can say here in this location and then it will printed the uh that particular line so I I Define the position which is the 216 okay let me also check that what exactly U showing that particular line so when I just do that 1216 the current position so which is tells us so tell it will tell you ke look what is the exact position and seek is defining the position set the position so when I just set the position when I just set the position and uh from there it will be starting so python designed the philosophy EMP prise code readability with its notable use of significant indentation so this is the line where is that okay yeah python design I want to read this one because I use that what exactly the position of um uh you know the first pythons so that was starting from it will tells us this one 212 but uh it will tell you the entire 212 entire pythons not the P I want to know that the position of P this P so that is the reason I just use the plus 4 and uh use it here 22 + 4 so likewise you can also check it and you know in case if you’re not write writing the plus 4 so what will be what will happen so it will showing that g dot and then values so you can just count it 1 2 three four after four position it should start then I’ll make it plus four that is the reason I did that okay so you can print it everything here so because I just use the C is equal to 216 that is the reason is printing after that okay that is the reason is printing after that so hope you understand how the text operation is working in Python programming language to handle the operating system operations in your computer so there is a module is available in Python which is the Os Os module so in OS module the lots of method is available to perform the different different operations so we can find it out this kind in any module I want to know that how many method is available you can use a DI function Dr OS so these are the supporting attributes so don’t check this one and here the ABC aert access CHD close chmod lots of method is available so every method have their own work so here in this video we will discuss about the few method and we perform some operations like let me just do the first one the OS do get CWD so get CWD will tell you like what is the current location your Jupiter notebook is working in some particular location what is that location there so the D drive recurrent learning and python so in case if I want to change the location how we can change it so this is the location here D drive okay D drive recurrent learning suppose I want to change it I want to enter in the directly in a python okay I want to enter not only yeah Python and exercise I want to enter in that location okay recurrent learning python exercise this location I want to enter it okay it’s already there in the python let me change any any other location back not in Python video I want to enter and Python tutorial so there is no any files is available I want to enter in that location so copy it that path go there and uh we can use it os. C HD change directory so you can provide the path here so when I just use the change directory your path will change and next time when you just check it os. getet CWD so you will get it the current location which is the recurrent learning video on python tutorials and some operation we can also perform is like um I want to make some directory I want to make some uh you know some folders directory is a folder so how we can create it uh current location is this this in the sense here nothing in no any folder is available I want to create any folder how we can create it mkd sorry OS do mkd and pass the values you can you can write anything uh I’m just writing temp directory temp di so when you just run it so temp directory will generate yeah temp directory is generated so with the help of os module you can perform some operation with your computer so that python is providing that kind of facilities other programming language is also there just I’m telling you the python have the OS moduel and uh in case if you have the multiple directory for example my current location my current directory is this and I want to create the multiple directory inside a directory like path is equal to I want to create um you know new dir inside the new di I want to create one more directory is a okay analysis okay inside analysis and then um uh we can say Titanic okay this folder I want to create it but if you’re using the. M KD let’s see it will work or not so os. mkdir path let’s see it will showing throw the error the system cannot specify the path because your current directory is this and inside that you want to create the multiple directories so which is not possible with a mkdir so different method is available which is a Mech DS Mech directories so when you just using the me directories so you can create a folder inside a folder inside a folder like that so let me show you yeah new di inside that analysis inside that Titanic so this way we can create it okay so in case I don’t want any directory suppose I don’t want a temp directory still there so OS Dot .rm and provide the path which is the temp Dr so that directory will delete RM di sorry rmd so that directory will delete as well so this kind of option is also available to you can also delete it okay there is one only one directory which is the new d new dir there is no any temp di because I deleted I want to change this name I don’t want you know this new IR I want to rename it so OS dot rename it okay so rename it so what is the file name new di I want to change it as a new only okay rename n a m e rename sorry so new di I just change it is a new so change it here so that kind of option is available so let me just do the last two method and after that I’ll I’ll show you the list you can easily explore it suppose my current directory uh my current directory is this current di let me just do it o.get CWD okay this is my current Di okay I want to perform some operation uh so like uh I want to add it like new Di and with all the locations right so how we can do it like inside a DI there is analysis folder is available so we can also join the path as well so OS do os. paath do join so my current directory current Di with whatever path you want to join it suppose I want to join with a new so it will be joined like this okay so you can perform the analysis and based on that so. path. jooin you can joining with the two One Directory with any other directory in case I want to create One Directory which name is a new which is already exist let me R OS do mkd which name is new let’s see what will happen so it will throw the error and saying that cannot create a file when that file is already exist so there is a condition we can also apply it okay if os. paath do exist and you can write it that new in case if new is exist the time in case if new a exist if os. path. exist the time will not create okay okay okay let me just try uh okay so it’s kind of if path the the different path is exist then you can create it like I want to uh this one is just tell you like the path is exist or not like I want to check that yes or no so it will show yes that path is exist so in case the new is exist inside that I want to create one uh location like here like here inside a new I want to create it inside new folder I want to create one more folder which name is uh data science okay inside a new I want to create it in a data science likewise okay let me tell you new okay temp Dr and then data science okay so like this live it let me make it the very simple I want to create new directory os. mkd which is name is new I want to create it but it’s already exist so it throw the error so what I can do if not os. path. exist new if it’s not there then it’s create otherwise don’t create so it will not throw the error in case new is not available so currently new is available it’s not enter inside the location but in case if it’s not available I delete it when you run it here so it will be create but inside nothing is there because just now it created okay so when you just apply this kind of condition if not os. path that exist then it’s created otherwise don’t create so in OS module lots of method is available so I just provided the link in a Jupiter notebook W3 schools you can also explore it like anything like I want to know that CPU count okay with a CPU count you can also use it how many CPU is there and you can also perform the operation there is a four CPU kind so likewise I want to also check that in my PC how many CPU count is there so OS do CPU count okay it’s not counts think yeah there is a 12 CPU count is there in their system is a four so likewise you can also explore it other method which is available here this is the last topic of file handling so here we will discuss about an different type of files like a pickle Json CSV okay so let’s create one dictionary so dictionary where inside some list is also available so this is the normal dictionary so pickle is used for preserving the data so like if you save this kind of data into any format like a Json format or normally the text format you can see easily right if you double click with a notepad you can uh see that kind of files but pickle is always store in the preserving method so like if I’m creating this kind of data as a complete data frame I want to preserve it and store somewhere so that in future we can also use it so usually this pickle we are using if you are generating any kinds of you know the model uh machine learning model or uh uh any any kind of model deep learning we are not using because for deep learning we have a separate extension is there so L take the example of machine learning if you created the machine learning we have a lots of steps is available and that entire steps that entire model uh steps we can preserve it with a pickle extension so here I’m just taking the one of the simple example which is dictionary I want to preserve it so again if you want to write any kinds of files we have to go with WB right in binary because it’s a pickle file and that have a two with two extension we can use it first one is pickle second one is Sav okay we can when you just store it uh uh that file will be stored in the pkl format so dick. py uh di. pkl the file is stored and you can’t see directly even if you’re opening on notepad you can’t see that kind of files so we have a two extension is available Sav and Pon okay so in case if you downloaded this file and uh you want to open it normal notepad any other any kinds of you know applications let me just download it and and I will show you how exactly look like so that was a dictionary that was a dictionary and now it’s visible like this actually that was not dictionary that was a data frame but it’s not visible properly if you want to see this kind of data again and if you share to anyone and they want to load it how we can load that kind of files so again we have to open first of all that uh files like with open Lim just use it with open file name file name is nothing but uh di. saav okay and we have to define the mode mode is equal to read in binary and pickle okay that we need one reference as F okay so pickle do load that F I want to load it let me store in the result values let me see result yeah so now we can see that kind of files so directly if you try to open it you can’t so because it’s store in the preserving method okay likewise we have also the another type of files which is a Json Json one of the data format where we can store in uh Json format right it’s a different type of format is there so Json always is working with the um curly brasses inside that key value payer option is available okay so we have a two types of data is available first one is uh structured data second one is unstructured data so this kind of data this word table kind of structured data but in case if you have a sector sector we have an HR and in HR the multiple set sector is there yeah we can say multiple type is there so you will you need to create one more table and then Define it HR how many types of HR is there right but the plus point of the Json is that ke name is a bob but the language instead of defining only one we can also Define the multiple languages as well okay and likewise inside the dictionary we can also make a dictionary so like the language is there inside the language I can also create one dictionary like in in a language I can also create a dictionary for example I can also make like this okay in English what is exactly the marks is there 45 so likewise they totally the unstructured we can Define the data in any way but if you have a table format so we have a limitations like English have a 45 a French have 56 the kind of we can also Define it so the Json is giving the lots of freedoms to Define our data set okay so nowadays the most of the data is available in the unstructured format so we preferring the Json extension okay so let me just show take it as it is yeah all right so we can also write it let me just create one normal files uh per . Json I just create normal file I’m just writing it here and dump now it’s dump and you can also do like this with with um you know with keyword you can also do that either or you can just open the file and then dump it okay so reading the files like file is already created the person. Json you can also see that so Json file you can easily see yeah they look like this okay so Json data is like little bit bigger even uh I can also show you uh some data set okay let me just go to uh covid 19.org one famous website okay covid 19.org okay I’m I’m just going with that okay this is a official website okay any other website is there co9 .org yeah covid 19.org okay I’m not able to find it out any H yeah yeah this is the uh one website is there when you scroll down and you scroll down so you’ll find it out the database here most of the data you’ll find it out in the Json format because unstructured data we can easily store in the Json extension okay see this is the format of the data so the most of the here the data is available like um you know the key and that values that is also considered as a key for that values this one is a key for that values like that we can also Define it like there is no any limitation to Define our data set if you’re doing with the same thing for a table so we have to create multiple tables for that so that is the reason Json is a quite booming and quite famous data type is there okay so we can also read it simply we have to read that data set so when I just read it look like this but if you want to see in uh same as it is the Json format so we can also apply the indent indent means taking a space for each uh sections we can say so to showing like this the name is a bob language and inside a language we have the different languages is there so we can also see that kind of data and and indentation it’s totally Upon Us ke how many indentation you want to pass it you want to pass the four it will be taking the four space otherwise it will be taking a two spaces so we have also uh another type of data which is the CSV is a quite famous I think uh uh everyone know about that CS V and Excel CSV is the comma separated values okay so here I created one complete CSV files so this is the field I Define it and this is the row and I want to create the complete table CSV tables which I will open on Excel uh software okay so I created the complete data let me first show you the data before writing the CSV format okay how it look like so row is look like this so this is the data I created it here and this is nothing but a field okay so field which is the name ear branch and marks so here I here I just just normally open it with with keyword student. csb is my data uh file name and I want to just write it and for next line I don’t want to Define anything and a dict writer when I just pass it and every time I will just write it uh write header and every rows that rows values one by one it will be passed into the um csb so the file is created you can also see that in a student. csb go back and uh we can see C student. csb is created here let me first download and I’ll show show you how it exactly look like the CSV file is created and the data will be look like this you can see okay name ear branch and marks so okay that is nothing but a field yeah name ear branch and marks that is a field and all the rows is also present here the name I Define it as uh Saga here I Define it a 2022 20 and Branch I Define it marks I Define it accordingly it’s created okay accordingly it’s created here you can see with the help of file handling we can also create the CSV file as well so likewise here I also Define it okay new line I want to add it so mode I make it upend and uh new line I didn’t Define anything so next time it will be appending that values so let me just refresh it okay uh here it will not refresh let me open in the same location here student okay so yes Manish math I Define it here okay Manish and Branch 2024 and math and marks I Define it here okay so likewise I also create uh the same thing for a data frame in case if you have uh uh this is the way of file handling techniques to create the CV file but one more way is also available to directly generate the CSV file like if I created the complete data frame with the pandas so it look like this I want to generate into the CSV so data set make sure that this uh this data set type this data type should be in a data frame pandas data frame okay so this is one is a pandas frame. data frame so if this kind of format of data is available you can directly pass data set in 2 csb if you pass the 2 csb so that directly will generate the files you can also see that yeah movies. CSV so the file will be generated in the Excel format sorry CSV format but in case if you want to generate the Excel format as well that is also quite simple why is not opening yeah it’s open okay by default is generating the uh index in case if you make it reset index Tex that will not visible there again uh this kind of things we’ll discuss when we start the pandas and numpy topic okay so let me show you how we can create the Excel file data set do 2XL you can Define it and uh you can write it here the movies do x x LSX that is extension previously it was a CSV that is a comma separated values Excel and csb both are different things both are different format is there okay when I just create it so you can see this one is a uh this one movies is the Excel which have a 5.07 KB that file size is little bit bigger compared to the CSV file this one is a CSV file but when you just click on it you’ll find it out the data is the same but only thing is that the Excel is creating their own format like this one is making at the board B this one is also making as a bold like that okay so this one is also the format of reading the any Excel file of CSV file I’ll just normally open it with the mode of R when I just make it mode of R and uh every time I just make it header and print it that sorry reader then and I print it one by one so you can see that the file so yeah so this way we can and why I just use this next because I want to just print it next one by one okay all right so hope you understand this all these structures but in case if you’re facing any kind of issues because uh this one I was little bit faster reason it’s the extra yeah we can say the different uh format of the data set is there sometimes useful sometimes not useful and uh I just explain the Json CSV and pickle maybe you also use different types of you know formatting but again the the structure the the process which I explain for this kind of formatting of the data set that will be the quite similar for that other format as well okay so hope you understand this video but in case if you’re facing any issues you can write it down in a comment definitely I’ll solve your problem so let’s first discuss about uh the topic which we’ll cover in object-oriented programming series Okay so so we’ll first discuss about what is the object then classes what is the inheritance and also we’ll also discuss uh Constructor polymorphism will discuss abstraction and encapsulation there is a completely a six main topic is there in object oriented we will cover one by one very first one what is the object and classes okay so class is nothing but so the uh topic name is objectoriented right right so first we’ll discuss what why the name is object oriented so object oriented is nothing but almost everything in uh programming language we consider as an object so like if I’m I’m a human my name is uh my name is X someone name is a y so that person is nothing but object so some classes is also there like the person is a x the person is a y the classes will be the human right we can say simply human human so suppose one car is there like here I I given the example as a maruti Audi BMW so these are a car the car is considered as an object where the car is a class this maruti AI BMW is an object the car is a class the same thing here so object which is defined here the Happy angry sad whereas the emotion is a class so the one real thing is which is really exist in a real life so we can say it’s object and some classes is also exist so class is nothing but it’s a blueprint of object whereas a object is a instance sub class instance is nothing but the example so object is a one example of a class so maruti is a example of car Audi is example of car BMW is example of car example is like instance of a that car so let’s understand in the practical way we’ll do it in the python okay so let’s do it in the practical way I’ll I’ll take the same example maruti Audi and BMW I will not take any other things so just consider here the maruti Audi BMW is an object and car is a class we’ll create it accordingly I’ll try to connect with that how programming uh in programming language objectoriented we are implementing so let me create one Jupiter notebook so it’s taking a time yeah now it’s created let me just take it oops concept okay so very first one is object and class we’ll try to Define it in a p in Python programming language we are defining with the uh class and class name so class name I’m writing here the car whereas the object will be BMW Audi and these are the things okay so car is a class so inside that we have a different different uh uh you know object is there so inside a car we can just Define it we can Define it the multiple functions so inside there is a class to multiple function is available right so the function can be the engine the function can be uh you know uh some indicate fuel indicator uh function can be the seat how many seats are there how many doors are there right so there is a door I’m defining the the function is a door so it’s very important to write it down here the self okay in Python programming language self is very very important whenever you’re defining any uh method inside a class so I’ll explain you later why the self is important for this self and then normal statement this car have four doors that’s it okay and and Def engine self is very important print this car have very powerful engine okay and uh let me also Define one more things is here uh seat self print normal statement this car have five seat yeah now then we just create an object so object can be uh BMW I’m defining it here BMW is equal it’s a object so car is a class so we Define the object like call the class and using the bracket and after that with the BMW what are the functionalities available you can directly call it okay so BMW do door so currently I just Define the very high level just door engine and seat but you can also Define it the very specific things is there ke in a BMW uh what is the engine is there so BMW have very powerful engine as compared to the marutti Suzuki or atata anything right so we can also Define the separate separating and we can call to that specific engine and specific seat okay and uh uh then I just call the B I just call the only door function so door will open right when I just run it so this car have a four doors okay so if the BMW i define it BMW do seat then it will call the seat only so this car have a five seat okay so likewise uh suppose if you have a different car car okay and I Define it car and uh T do door when you just call it so you’re not expecting that it should be the answer is a four seater a four door there is only two door right but here I directly Define it the four door because it’s a uh you know just default value I just pass it that I printed the values but you can pass the arguments if you just calling the uh door function and your object is a thar so definitely it should it should be pass only the two door not a multiple door is there so likewise we can also Define it so we can pass the arguments here is showing the four door because I Define it so here my main Moto was that ke how we can create a class and object so car is a class door method seat is a door engine seat is a method I can directly Define it here this is nothing but a class and these are we are calling the method and these BMW is nothing but an object BMW is nothing but a object object calling okay so this way we are defining here the the confusion is that what is the meaning of self and uh in case if I’m not writing the self so what will be the impact here so suppose if I’m deleting the self let’s see what will happen throw the error it throw the error is saying that the car. door takes zero positional arguments but one was given so that means so here the self is very important to Define it because so by default when you are creating the object it’s passing some arguments okay so that’s why it’s saying that take a zero positional argument but one was given but means here is passing some arguments but uh uh you know but I didn’t Define a I didn’t Define any positional argument so here I didn’t Define anything so that mean we have to define the self so what is the use of Self in case if I just use it here the self what is the purpose of that so self is a kind of self is a kind of one parameter so it’s using for passing the references so here I Define it self is a parameter is a reference to the current instance to the class and used to access the variable belonging to the classes so it’s very simple like if I have any variable uh the variable is um door is equal to four instead of defining here directly the four I just Define it as a variable I pass it the door okay I pass it the door and uh the same thing for a seat I also Define it seat is equal to 5 okay I Define it the seat okay all right so when I just run it so you’re getting the same answer nothing will change because I just create the one variable and Define the variable here same thing here I create the variable define it here but in case I want to use this door variable in a seat function is that possible so absolutely not we can’t can’t do it because it’s a local variable so it’s useful only inside that function any other function if you want to use it it’s not possible there so how we can use it so like here I want to instead of writing here okay instead of uh uh instead of writing this car have a five seater and door and doors are door is it possible to write it so it thr throw the error if you’re calling the seat function definitely throw the error yeah it’s saying that door is not defined in a seat function why it’s not defined because you can see here this car have this uh this this function have the variable seat but door don’t have but if you’re using any kinds of variable and attach with a self so it’s become a kind of global for the entire classes not outside of that so self is kind of passing the references so that it can be used inside a classes self. door instead of writing the door if I’m writing the self. door you can access why not access okay uh self. door is not accessible it should be self. door self do okay let me also Define it yourself I think half of you can’t use it door is not defined mhm okay so it’s throw the error in the first U function uh bmw. door okay so here is throw the air because I Define the self. door and here I’m calling the uh one door so that’s why throw the error so now the problem solved I use a self door and that variable I can also access easily any other function as well but make sure that that all the functions should be available in the same classes if the classes are different so then it create the problem but again that problem have also the solution is that uh we can use the inheritance that we’ll discuss later okay hope you understand that how the self parameter we are using what else we can also discuss it here there is one topic is called as a method and function and uh uh some you know some myth is there ke method and function both are the same uh both are the same or different and if it’s same then why we are using the two different name right it’s very confusing things so method and function both are same first of all let me just clear it it’s the same nothing different so only different is that if you’re creating any kinds of function with like uh Def and uh some function name is like a fun okay let me just write it there if you’re defining the function def function name is a great okay this is the function name and inside that whatever you want to write you can I’m just writing the pass so this one we are calling the function this one we are calling the function but in case if you’re defining any class okay class name is a and inside that if you’re defining this kind of function and with a cell parameter which is mandatory in objectoriented programming language if you are writing in a python so that time the grd become a method okay so here grd we are not calling it a function it’s a method so the difference is that the function and Method both are a same only when we Define the function inside a class is called as a method let me also write it when we we are defining the function inside the class we are calling method very simple so method or function both are the same only thing is that when you’re defining the function inside a class we are calling method there is also one more perception not a perception one statement is quite uh popular in Python programming language only which is in a python python is an object-oriented programming language that is true but almost everything in a python is an object with their properties and Method now it’s very confusing almost everything what is a mean almost everything so that means if I’m defining any variable that is also the method uh that is also the object yes as I said like when we start the objectoriented programming I said ke uh almost everything thing in uh in the world which is really exist is called as a object right so here if I’m defining any kinds of variable this normal variable a is equal to uh 15 and B is equal to hello these are two variables so according to that statement can I say that A and B both are in object it’s true both are object so why it’s object see if it’s object then definitely some classes will be there right because python is objectoriented programming language I said that A and B both are object that means some classes will be there so when you just check the type A so definitely you will get a class actually you writing in the Jupiter notebook that’s why it’s not showing that complete statement when you just print it print a so you’ll get it yes so int is a class of a so a is object integ a class some method will be there some function will be there method will be there not function okay because when you define the function inside a class that become a method so where is the method so when you just using the DI function which we used in I think last classes uh for OS module so di of a you’ll get it all kind of method these are attributes which we are using in object oriented in in class and object and when you scroll down you’ll find it out the object as well uh sorry method as well these are the method two type real image everything right so hope you remember in the uh data type um in string so lots of method is there I I make I separate it okay these are a function these are a method a method is always calling right method is always calling so here when I just use the DI R of B of B you’ll find it out the lots of method I think some method you already aware about that so like uh join we usually implement it split we usually implement it where is that yeah upper lower these we are implemented these are a method so if it’s a method I want to call it how we can call it here so B is a object okay I want to call one method Dot because B is object if you’re calling any method we have to use a b dot what is that upper so this is the method so when I just run it yes it’s working but that classes is the inbu classes so int string di list these are inbuild classes so hope you understand this concept is that why I’m saying that int uh why I’m saying that almost everything in a Python programming language is considered as an object a Constructor is a special type of method which we are defining with the init so I think we already discussed the init in package and module so there we didn’t create it in a class and object but here the Constructor which we defining that will be the class and object so the Constructor is executing when you’re just creating the object of the class so even don’t need to manually call The Constructor so let’s do it practically this is not a theoretical topic let’s do it practically here I’m taking the same example the car and what I just discussed let me just do the copy paste and try to just create one problem and that problem will solve with the Constructor okay so these are the uh code and here I Define the door and that that self. door I’m just using inside the uh yeah the seat yeah in the seat method I’m also using the self. door but what happen if you’re not calling the door method and you’re just directly calling the seat method so of course it will be give the error so here is showing that bound method oh okay because I Define it the door method and door function uh door variable both are a same so never do like that uh so better I’ll just do a doors okay and here I also use doors so here you’ll find it out you’ll get the error all right let me just remove it this one you’ll get in the error because you didn’t call the door method and you’re using this door variable so in that situation what is this uh option for you because anyhow you have to call the do method then you can use whatever you have Define inside that particular method so avoid this kind of scenario we are using the Constructor so Constructor we are defining with underscore underscore and it underscore underscore inside that cell parameter is always be there and whatever you’ll write print this is Constructor okay this is Constructor so whatever you’ll Define inside the Constructor this in it and that will automatically print so let me just remove it both okay let’s just create uh create the object BMW is equal to car so when I just run it automatically this method is run it’s executed it even I didn’t call it here so let’s call the BMW BMW dot the seat method seat method if you’re calling so there is a variable is self. seat okay self. seat which is Define it uh Define it here here directly and seat number better uh let’s change the variable name seat number so don’t make it the variable name and Method name are same otherwise the conflict will happen and you will be confused that why the getting the different error yeah different answer okay the better of door I’m also taking the door number yeah number of door okay number of Doors number of doors okay so here when I just run it and check the error car object has no attribute of number of doors the reason behind that because I didn’t call the uh car method and directly calling the seat method here so the seat uh there is a two variable I’m just using SE seat number which is defined in the same method but the number of door is defining the different method so avoiding this kind of conflict if you’re just using the same variable in the multi multiple method so don’t use it here I can directly use it inside a Constructor because Constructor will always always execute and you can directly call any method you not depending on any method here so when I just run it yes this this car have a five seat and doors are four so right so this kind of Constructor we are calling the non-parameterized Constructor so the Constructor is also defining the two types the very first one is a parameterized second one is a non-parameterized parameterize simple you have a parameter non-parameterized you don’t have a parameter right so which I Define it here this one is considered as a non-parameterized Constructor red Constructor and if I want to make it a parameterized Constructor whatever you passing the number of doors and uh seat number so that you can pass as a parameter so let me just Define it and uh we are doing the Constructor let me also make the heading properly here so this is the Constructor topic okay so I want to make it parameterized Constructor here so this is normal non-parameterized Constructor let me just remove it my target is to make it parameterized Constructor so whatever is Define the number of doors so instead of taking the manual Valu is the four I’m taking as a parameter wise uh suppose the door number okay door number suppose that variable I’m just taking it and at the same time so all the variable which I Define it even the self dot seat number that I also take it inside the Constructor itself okay let’s take the seats number let me take the number of seat directly number of okay so uh here I’m getting the values as a parameter so let’s not take it this one now so this is the normal method I’m just making it so inside a door I’m just printing the number of doors engine just normal statement and Method and seat and we are printing the seat and doors both so here I don’t want to make it manually four and five let’s make it some Dynamic way so in the place of four I’ll just pass it the uh door number and here in the place of five I’ll pass it the seat number so whatever value will be store in the seat number and door number that will be that will assign into the self do number of doors and self. number of seat so here when I just pass when I just call the Constructor when you don’t need to call the Constructor automatically call let me just create the object of it BMW is equal to car and here you have to pass the parameter because if you not you have to pass the argument if you’re not passing the argument it will throw the error what is saying that the car do in it missing two positional argument which is the number of door number and seat number so I’ll pass the two arguments let me pass the four door and five seater okay four door and five SE when I just run it so this this is Constructor that statement is run that means there is no any problem in the Constructor so now when I just pass the when I just calling any method like bmw. seat so that running properly okay bmw. seat oh the core object has no attribute seat number okay it’s not a seat number it’s a number of seat okay when I just run it yes this one properly working the main Moto of it here if you are just defining the parameter inside the Constructor it’s become a parameterized Constructor and if you define the parameter of course you have to pass the arguments okay and uh you can also make it default parameter as well so you can make it get zero in case if I’m not passing anything if I’m passing the four and five of course I’ll get the four and five as a seat number of seat and number of doors but in case if I’m not passing anything so in the time is taking 0 0 so that default value we can also Define it so this way we are doing the Constructor let’s first discuss about the definition of The Inheritance so inheritance is a mechanism which inheritance is a mechanism in which one class classes acquire the property of another classes so there is so many examples available for inheritance so I’m just took one of the example of uh parent and child so likewise the child is always acquiring the uh you know all the kind of property and uh other stuff of uh his father so the kind of uh this kind of classes this child this classes we can say the child classes okay and it’s we are also calling the derived classes it’s already mentioned there derived classes and uh we also calling us yeah child classes and and this one we are calling the base class we calling the parent class parent class okay so likewise we have a two different name we are using it so there is a multiple type of inheritances exist in the objectoriented programming language okay I already mentioned there the super class we also calling sub classes we are calling of this child okay so there is a multiple types of inheritances exist single inheritance multiple inheritance multi-level inheritance hierarchical inheritance and Hybrid inheritance so here the the complete map of the single inheritance and multiple all kind of inheritance map is available so we will discuss about the Practical implement how we can perform the inheritance concept with the Python programming language okay let’s jump on the coding yeah practical implementation okay I required one classes uh let me just take a very simple classes is U father okay so I’ll take the very uh you know real life scenario situation where you can easily relate it like I create a I will create father class I will create a child class I will just create object of the child so that you can easily real relate with the real life example father and so whatever if you want to create any kinds of Constructor you can otherwise it’s not required currently okay so we’ll create one method so method name is like the father have car okay so the child can acquire the car car and self is very very important self and let me let me also pass some parameters car model your model I’m just passing it here and just normal statement okay father have a car here I can also Define the model as well so this is one class I’ll also create one more class which is a child okay child and here I will inherit the father let me first create the child later I’ll inherit how to inherit I will also discuss in a deeper way as well so def a child have a bike okay let me also pass the self and bike model yeah yeah model we can say model and print the statement is I have a bike and that also Define the model as well simple so I’ll create one object the child object the ra name is Rahul Rahul is a object of child class now I create it if I want to call any method which is available in the child class I can easily call it Rahul dot bike okay I can easily call it so now when I just run it you’ll get the statement is I have a bike so whatever bike he have so we can easily get it okay so here we can simply perform the operation and also check that key uh this one is running or not there is a error why it’s Error because we defined one parameter but didn’t pass any kinds of arguments so I will pass the arguments what kind of bike you have I’m just passing the fet simple so I have a bike FZ but can Rahul call the car method is that possible so no Rahul cannot call the car method because it’s available in the father class so I can simply create I can simply inherit that father class in a child class so you can just create just round bracket and inside that whatever class you want to acquire it you can directly write out there that class name so I’m writing the father so when I just writing the father inside the child bracket that means I’m just acquiring the all the property of child uh all the property of Father inside the child so when I just run it so I should get the answer now okay so father is also have one parameter so I have to pass the arguments so I’ll just pass the arguments as like maruti simple maruti okay when I just pass it so father have a card which is a maruti so simply Define it here so one class acquire the property of another class so property of another class in the sense property can be any variable can be any method can be any function method and function both are a same so you you can call to any kind of the inherit Constructor as well you can call it okay so this kind of inheritance we are calling the single inheritance we are calling single inheritance we can just Define it single inheritance simp so let me also take one more example of another inheritance and after that I’ll Al assign you the one kind of task for you you can try it and check that key uh you can you know you can easily do it this inheritance sing multiple or multi whatever you can do it or not so single inheritance is done and now I have to take some complicated in inheritance let me take the Hybrid inheritance because when I just take this hybrid inheritance so hybrid will be cover the hierarchical inheritance which will be this and uh it also cover the multile inheritance as well so I’ll just go with Hybrid inheritance and uh you can also do the practice of multi-level inheritance and hierarchal and multiple separately as well okay let me just also Define the uh here headings so that you can also do it so you will get this Jupiter Notebook on GitHub just go to the description you’ll find it out one link just go there and find it out this this Jupiter notebook code okay so uh I’ll go with the Hybrid inheritance inheritance inheritance okay it’s one sorry okay so Hybrid inheritance I’ll just try to create it I’ll just take this uh same example this one okay now this one is a single inheritance I’ll also create one more class which have simply mother and Def car self model not a model I’ll not a car I I’ll take something else uh scooty okay scooty suppose mother have a scooty uh so I can also Define it here the self and model I will not pass anything I can directly call the scooty and print this normal statement okay so mother have scooty okay simple so child here the child is acquiring the father only and uh let me also create the object is Rahul is equal to child and Rahul will call to father rul will call to sorry not a father rul will call to car r can Rahul can also call the bike as well so he will not get any kinds of error okay so model is required so I’ll just pass it here okay so maruti I’m just passing the same thing and there I’m just passing the F said so this one is working but if a child try to acquire the property of scooty Rahul do scooty so you’ll get the error while getting the error because here the child is not acquired the property of mother so I’ll here I’ll try to just acquiring the property of mother as well just do the comma and pass the mother so what will be happen so child is acquiring the property of both mother and father both okay so simply you have to just pass the both the classes inside that bracket uh which one which class you want to inherit so this kind of inherit this kind of hierarchical uh this kind of uh inheritance we can say it’s a hierarchical inheritance because I have a father I have a mother and here is a child so it it acquire the property of father and mother okay so when you’re talking about uh other inheritance like if you have a multiple things so so this it’s not a hierarchical inheritance we can say it’s a multiple inheritance multiple inheritance okay so when you’re talking about the uh you know any hierarchical inheritance so one kind of class should be there so let me also create one more classes and father and mother both can acquire that kind of property so we can say uh we can say Define that um uh property we can simply we can say property so property can acquire in inside a property function so father and uh mother both can acquire the classes so we can also Define it here so that become the hierarchical inheritance so upsider one we can say it’s a this one so this one we can say it’s a hierarchical inheritance and uh in inside one we can say this downside one it’s a multiple inheritance so let me just remove it clear all the drawings yeah so let’s create one kind of class and just Define it this one is this hybrid this currently it’s a not a hybrid this one we can say it’s a yeah this one is a multiple inheritance I can also Define it here multiple inheritance multiple inheritance I have to also pass The hierarchical Inheritance as well inheritance okay so currently I just use the uh multiple inheritance let me also Define The hierarchical Inheritance as well so I can just take it here one of the classes which is okay property okay okay properties I can M it because maybe I think some in build function or in build classes can be so I will not take the property I’ll just take the properties I’ll create one function is a uh okay land Square self I Define it here so that property father father mother both can acquire it at the same time child can also acquire it so I can also Define it here uh just normal statements so we have five acre ACR I think we can call call it property in India okay the normal statement is there so currently that properties classes cannot uh you know it’s not connected with a father and mother if they want to acquire it they can also directly pass it here the properties so this is just a normal example how the all kind of inheritance is working properties okay so simply uh properties that spelling is Miss wrong I think okay properties so there is no any error so in case if I’m creating the object of father and mother anything So currently uh the object of child is already present so let me also directly call that Rahul do properties Rahul do land Square so when I just use the land Square I don’t need to pass any kinds of arguments so Rahul can also access it why father and mother so same time if I creating the object of father and mother like f is equal to father and uh F do land square if I’m just calling it so you can also access it so inheritance one of the simple topic of objectoriented programming language so here I just use it the Hybrid inheritance inside a Hybrid inheritance so multiple and hierarchical is a covered so multi thing is remaining in the multi-level so you can also try it and let me know if you’re facing any issues but I’m I’m I’m damn sure you will not face any kinds of issues because hybrid is covered kind of all kind of uh levels because the multiple is already there so you have to just increase one of the labels so it become a multi-level inheritance let me also create one heading multi- inheritance okay so polymorphism is nothing but like many form the simply we are calling is the many form right many form we can directly say so when you’re talking about the definition of the polymorphism is simply if you have any kinds of function and the same function name being used in the different way let me just remove it that annotation yeah the same function name being used for a different types so not only the function uh usually we are using for a function that we are also calling the method but we can also do the same for operator as well so polymorphism can be achieved in the many way so the very first one I think you already aware heard about that that is Method overloading method overloading and uh the second one we are calling method overriding okay so and we have also the another type is also aaable uh that uh we have Operator overriding Operator overloading Operator overloading and uh we have also one more type is there the duct type okay why I mention there the operator overloading and duct type here because in this video and in the series we going to discuss about the method overloading and method overriding which is very very important um in the polymorphism perspective but you can also learn it the method over loading and duct type as well but if you want any if you want a video for uh operator overloading and duct type I can also make it it’s not much as much complicated okay so these are the way to achieve the method or uh to achieve the polymorphism concept let me also write it here this way we can achieve polymorphism okay so uh polymorphism we can also understand it there is two way the first one we can we can try to understand with without classes okay without without classes which I will discuss in this video okay without classes and we also discuss in with classes as well okay so with classes like here method overloading and method overriding that we can do it with classes but let’s understand it very simple way how polymorphism is working in um you know normal examples so let me also let me take one heading polymorphism okay startingly I will not make it much complicated overloading overriding we’ll discuss later but let’s understand it how polymorphism is working with a simple function without any classes polymorphism okay let’s say for example if you have um you know inbuild function is a len so Len is a function if you you pass a simple statement is hello okay so it will give you the answer is the length of five length of hello which is uh five but in case if you’re passing the length of any uh list 5 6 8 9 there is no any restriction to pass any kinds of data type I can directly pass a string that is also acceptable I can pass a list that is also acceptable if I’m passing Apple dictionary set anything that is acceptable so the one function have a multiple form to define the length of uh the length of container that container can be the string that container can be the list dle anything suppose if I’m defining any function here the def def add function I’m passing the values is x y and Zed okay x y and Zed and just uh returning the values return x + y + z so when you call this function the ADD and pass the values is 4 comma 5 comma 6 then you’ll get the answer like addition of all the values which is a 15 but in case if you’re passing only two values two arguments but you define the Define the three parameters but if you pass the two arguments definitely you’ll get the error but if you directly Define some uh you know default parameters which is if I’m defining the none here so that is acceptable here uh not a none uh none type cannot be added let me pass a zero okay pass zero so you’ll get the answer is 5 + 4 so the same function I can add two values the same function I can add add three values as well so here the add function being being like uh the same function is uh you know working for multiple forms so we can use it right so this there is a two techniques is a method overloading and Method overriding so that is a two different totally different techniques we’ll try to understand it and do it in practical way so how exactly the method overloading is working so let’s say for example if you have one class okay class and the class name is a uh for example is a cal So Cal class so inside a cal clock I can Define it multiple methods uh multiple methods but the name will be the same so the name is like def me method name is ADD I can pass the parameter is like X comma Y at the same time I can also Define one more method which is ADD and this time I will pass the parameter is X comma y comma Z okay okay so if you have a two different method is available but the name are name are same so when you create the object of the class so the class name is suppose C Class name is a cal and object is a c Cal okay and uh C do add if I I’m just calling it if I’m calling the add function with three parameter 5 comma 7A 8 then definitely you will get the addition but the same time if I am just calling the addition U addition of only two number suppose if I’m not passing the eight okay so function is already defined the add function is already defined so definitely this function should call but in a python this kind of you know normal overloading is not supporting the reason behind that the python is a interpreted language and it always take piing the current positions current positions values so here the current one is the add which is defined with the three parameters and if you pass the two parameters the previous one is not accepted it’s being overloading but if you’re defining if you’re passing the only two parameter it not able to call the previous one so the complete overloading is not acceptable in the Python programming language let’s try to understand in the Practical implementation okay uh the topic is Method overloading let me just uh write it down the heading here method overloading okay so the class I Define it the same example I will take it class calc okay inside a cal I’ll uh I’ll Define the uh function add and pass the parameter is a comma B okay and uh make sure that you have to pass the self uh par meter which is passing as a reference which is compulsory in in the Python programming language I’m just passing it here return of A+ B okay so and then I’ll Define the ADD and pass the uh parameters a comma B comma C okay there is three parameters and uh return the values A + B + C and me also Define a without parameter def add and self inside I’ll just pass the A and I will return return e that’s it so very simple example is there the method overloading so method overloading let me also write it down the definition here a see okay uh method name are same but different parameter method name are same with different parameter okay so here I make the same thing method name are same but the different parameter if I’m just I the structure is ready now I’ll create the object object is let me just see take it as a c is equal to Cal okay all right so here Cal is a class and the C is object I will call the method add the C do add and pass the parameter 4 comma 5 comma 7 so I’m expecting the answer is uh 19 5 + 4 9 + 7 16 so yes the answer is correct the 16 but here I pass the three parameters so definitely this method is run okay but in case if I’m passing only the two parameter what will happen so if I’m passing the only two two or ments this one is arguments okay let me also write it down here this one is a arguments and what you are defining is a parameter okay so here I’m passing the only two arguments and uh the line number five is already defined the um you know only two parameters so I’m expecting the answer should be nine but here is the getting the error it’s saying that the missing one required positional arguments which is C so why it’s showing this kind of error the reason behind that you can see here so the last method is defined three parameters and I pass only the two arguments so it’s not able to check the previous one because of the Python is a interpreted language so if I’m passing the parameters it taking the current one for example if I have the a is equal to 7 and a is equal to 8 so if I run it so it’s being completely over overridden okay so if I’m printing the a so it will getting the answer is eight so what will happen is the first eight is a store in the first seven is a store in a variable when I’m just storing the eight in the same variable so what will happen the previous values is removed so the same thing happening is here so previous value is not considered it’s taking the current one only so what I can do uh so simply the method overloading is not completely acceptable in the Python programming language but if I want to achieve it so we have a you know different way we can achieve it see in a python everything is possible but something is direct or something is indirect so the directly method overloading is not possible but indirectly you can use it so what I can do it here if you if I have a three variables so all three variables I Define it a b and c but make sure that you have to Define some parameters I’m I’m just defining it here zero okay I’m just defining it here zero uh or else or else I can uh directly Define it here is equal to none nothing is there because I I’m not defining anything right so uh is equal to none but a is not equ equal to none here so because if I’m just passing the only a values so it’s not is equal to none okay uh so it’s not none is equal to none it’s is equal to is equal to none hope so it’s correct okay all right so uh this way is not possible so what I can do it here let me just uh okay so let me take it as it is now I’ll Define it a different function here so what I I’m expecting that what is my target my target is very simple is that if I’m passing the three parameters it should be the addition of three number if I’m passing the two values it should be the addition of two if I’m passing the one values it will be just print as it is so how is possible I can Define it the same class let me just Define it C A LC class and Def add and uh pass the self and Define the a comma B comma C simply I I I can use it here the condition wise so if the a is not is equal to none okay and B is equal to is equal to none and C is equal to is equal to none so in that time I will return simply a okay and L if if a is not equal to none and B is not equal none and C is not is equal C is equal to is equal to none so in that time I will return a + b okay it’s not a comma it’s a and at the same time Al if a is not equal to none and B is not equ equal to none and C is not is equal to none in this time okay I will uh return the value A + B + C great so let me just create the object C is equal to calc C1 let me just check it because the previously I Define it so I don’t want to mix up here C1 is equal to calc all right C1 dot add if I pass the three parameter 5A 4 comma 6 Okay so you the answer is a 16 what happened def C where is that def C line number 20 where is the line number 20 oh oh sorry oh it’s not a def it’s a class sorry it’s 15 I’m getting the answer is 15 okay previously it was yeah 15 and if I’m passing the only two arguments it’s giving the answer is okay the C positional arguments is defining it here uh okay 11 line number 11 if I’m passing the ADD and pass the parameter a comma B comma C okay is equal to none let me Define it is equal to none let me Define it is equal to none and let me Define it so the 5 + 4 is getting the answer is nine so if I’m passing only one arguments five that’s it boom right your how it’s happening because if I’m passing the values and in case in case if I’m not passing anything let me also defining else is here none so if I’m not passing anything so it will not give the error it getting the none so what will be happen so if I’m not passing any parameter so default values is none none none okay so all the condition I Define it ke if one values is present a is present it will be return B A and B both are present it will be return c a b c both are all three are present A plus b plus C is working is here and in case if you’re not passing anything so the answer is none so this way method overloading can be achievable but directly the concept was method name are same but with a different parameter if you define it so that is not achievable directly in Python other programming language yes it’s achievable in Python is not possible so the next topic which we have to learn it here method overriding which is mainly used in almost every applications so in the last video in meod overloading what we discussed is ke the same method and same uh different parameter was there method name was same but different parameter but here in the polymorphism is being little bit more complicated method name are same and the same parameter as well right so the problem was the previous uh topic is the overloading that was not acceptable completely so the question is how it acceptable is the over overriding because here the method name and that parameter both are same it’s acceptable because the classes are different you can see here so there is a class is a shape class inside a sh shape class in there is a class uh sorry there is a method is a draw draw draw and there is no any parameter is available here right so I can say the same method but and the same parameter as well but all three method are available in the different different classes like Square class Circle class and he hexagon class so this method overriding is achievable with the help of inheritance concept so we already covered The Inheritance you can also just refer that videos as well so let’s do in a practical way how method overriding can be achievable in polymorphism topic okay let me just write the heading here method overwriting okay so suppose if you have a class class name is a father and uh father have um you know uh one method uh car okay and yes self parameter is very very important in object oriented in Python if you’re writing the code and a simple statement is that hey I have a car okay the car name you can also Define it here suppose the car name is um uh you know uh BMW okay simply BMW and there is also one more class which is a child and child have a bike okay and let just just normal statement here I have uh um sports bike Define it here uh the same thing is a BMW okay the father have a car and the child have a bike if I’m just calling it here uh you know the object of a child simply Rahul is equal to Rahul is a object the child is a class okay Rahul do bike and and uh uh when you just uh call the bike then you’ll get the answer is I have a sports bike which is a BMW and you can also inherit the father as well okay and if you inherit then Rahul can also access the property of a father so Rahul doar if I’m just calling so you can also access the car as well so Rahul is saying that I have a sports bike which is BMW and he’s also saying that hey I have a car which is is BMW so there is no any overriding till now but if I’m creating the a car method inside a child which is also present in a father car and the same method name and the same parameter like here I didn’t pass any parameter and in the child car I’m also not passing any parameter here so when I just writing here the different statement I have car Mercedes okay Merced is bench so here if I’m just running this this method the car so this time it will not calling to the father it will directly call which is available inside the child so here the statement is being changed I didn’t change the calling method here is the same thing as a car previously was also car but here it’s not showing the BMW it’s showing the I have a car which is Mercedes previously it was showing the BMW why it was showing because it was not present at that time and it inherited from the father and that is the reason it’s showing that yes I have a car which is BMW actually the child don’t have a car fathers have a car but now the child have their own car instead of writing the I have a car I have my own car okay Mercedes-Benz so the here the car method this car method is overridden from the father car so this way we can achieve the overriding concept here so there is also the techniques is available the uh operator overriding so there is also one more issues is exist which is uh if you’re creating the class we always creating the uh Constructor which is defined with underscore uncore init so every classes when we Define The Constructor the always the name are in it so when you define it so by default that init is being overridden but sometimes we have to we have to use both the Constructor so in that time how to achieve it how to solve that kind of problem so we’ll discuss in the next video so if the method overriding we have some issues like if we are creating the Constructor and uh uh how we can if the Constructor is also overridden then how can we use the previous Constructor yes parent class Constructor so super function is solving that that problems the super function is used to give the access to method and property of the parent or sibling classes so it’s kind of giving the access it’s accessing related things is there so this things you’ll understand in the practical way okay it’s not a theal topic so let’s let’s discuss about some scenarios where super function we can implement it let’s say for example I have a class okay it’s not a capital letter I have a class class name is um uh same is the father and the father I have one Constructor this time I’ll just use a Constructor last time I didn’t use any kinds of Constructor there so I’ll use a Constructor in it okay so make sure that you have to write a self here self and then just write it uh some some variable uh self. car okay that car name is I I will use it um I’ll use it maruti very simple simple car is here maruti Suzuki Suzuki okay all right and uh a function name is um you know info so inside that I’ll just writing here print I have a car and the car name I can also mention here the self dot car very simple okay same time I’ll also create one more class that is child the child have a Constructor uh the diff in it I’m so sorry yeah here I’ll just use it and it I’ll just pass it here so so you know that if you just um you know apply The Inheritance concept here it will be over done right so let me just complete the code and after that I’ll apply the uh inheritance concept here Def and and then uh self. bike that bike name I can also Define it here Duke okay Duke okay all right and then the same time def info okay I’ll just use the same thing here same function info okay and same parameter here I just didn’t use any parameter I here I’m also not using any kinds of parameter I’ll just use it here I have a bike okay I have a bike let me just write here the bike info right bike info I have a bike and and and I can also Define it here the self. bike simple all right okay let me just create object is Rahul is equal Al to child okay object is created Rahul do bike info I create the object yes I have a bike which his name is Duke all right so here I didn’t apply any kinds of inheritance concept so let me just use the inheritance when I just use the inheritance so I can also acquire the property of father so when I just use it here the self dot okay self dot uh sorry not a self do father I just use it here the father I’m so sorry yeah so yes Rahul can access the property uh yeah we can say the function which is bike info I can Rahul can also be access Rahul doino as well which is nothing but a car info let me also write it here the car info okay car info can also be access what is the issues here the child object ch object no attribute of the car why why it’s showing that no attribute to the car because here the two things is overridden here I have a car info okay that I can also access it but the problem is it will be needed self. car which is not available in this init okay let me just Al let me just write a very simple statement I have a car that’s it okay so you’ll not face any issues I have a car that’s it I have a car so Rahul can also the acquire the property of car info can be acquired but if the Rahul need any kinds of variable from the init from the init like Rahul want to access Rahul want to access the a car can yeah bike let me first take the bike bike yes Duke can be access simply can be access here can can Rahul be access a car which is available here is it accessible the answer is no Rahul cannot be accessed the car uh is it required a function here oh not a function okay sorry rul cannot be accessed the car because this in it here I just use the init because of this init and here I also use the init this is the same method is available with the same parameter it’s become overridden in a child class so you cannot be access it but still I want to use the car uh car variable I want to use it how can we do do that so you can use the super function super function super function. net super dot yeah and it so when you just use it uh okay there is some issues I can directly use it here super super is a function yeah and then use it in it okay uh sorry in it is not as in exactly this in it you have to write it here in it yes Suzuki I can also access it so I I can I I can’t directly write it like this you have to print it so when you just print a car bike you’ll get the bike and if you print a car you can also access the car so the simple is here when you just write it here the self. bike that means you can uh self bike you can easily access it because of this init is inherited from the father in in it so that means it’s become overden so the previous one is not access ible but still if you want to access it the super is nothing but your parent you know from where you are acquired it this is applicable for any kinds of hierarchal um inheritance any kinds of inheritance if you just using it the same concept will be applied the super is like child super is nothing but a father so the father variable can also be accessible if you are using the super function okay super function if you just using it you can access it and now if I’m just writing it here um self. car so that means you can access it so here I can see I have a car which is a Maru Suzuki okay I have a car is the maruti Suzuki but again it is applicable if you’re just using the same function is a car info okay and uh self is very very important car info and just write it here um I have a car which name is I can write it here uh B BMW okay so here showing the BMW because this same function is overridden okay but uh this function is not available definitely it will go back from father class and and use it but here the self. car is also available and uh which is available in a Constructor and Constructor is already overridden to to overcome this kind of problem to solve this kind of problem we are using the super function so super function is nothing but the giving the access the variable method and uh any kind of attributes from the super classes yeah father classes so the definition is also saying the same thing the super function is used to give access to Method properties of a parent or a sibling class okay the super function return return an object that represent the parent class okay so here super is represent that I I’m I’m a parent class okay whatever you need you can just call me so this way uh super function is working so let’s directly jump on the Practical implementation here okay so this this topic is very very simple uh we’ll just create the inner class we’ll just create outer class and try to call it how we can call it and what is the procedure we’ll uh discuss it step by step let me create one class class name is very simple just laptop okay inside a laptop and just for a confirmation um you know so that we I just call it so that we’ll get a confirmation so I’ll create one Constructor because Constructor is automatically called we don’t need to call it make sure that you have to write a self here and the statement this is this is laptop class just normal statement and after that it’s on you if you want to create any kinds of function you can create it but I’ll directly create a class here so class class name is HP okay inside that laptop there is a class is HP and uh again I’ll create object uh sorry not object Constructor I’ll create a Constructor and Define some name here print this is HP class inside the laptop class okay it’s very simple laptop class great and we can also create one one more function function name is info okay and this normal statement here hey this is is info function simple this is info function so the creating the inner class and outer class is really very very simple just we have to Define it which one is inner class and which one is outer class so this one you can understand like this look like outer class yes it is outer class it is outer class and this one we can say it’s a inner class okay sorry inner class all right so how to call it like my target is to call the info function which is available HP that HP is available in a laptop so let me first create object of laptop L is equal to laptop laptop okay or create it and uh if you create it the object so Constructor will definitely call yes uh this is laptop class it’s a class yeah this is laptop class okay and I want to call the info function fun which is available inside HP so H is equal to l do HP okay l. HP right because HP is not you can’t directly call the HP because which is available in outer class so first you have to call the outer class and after that you can call to the another uh inner class okay uh the laptop we don’t have any kinds of attribute okay all right then I can directly write here okay sorry uh HP is a capital letter yeah HP class this is HP class which is inside the laptop class and with h i can directly call the info that’s it so hey this is the info function and this is the one way to call the a function which is available inside the inner class but we can also directly call it here ke we directly create the object is H is equal to laptop okay dot uh HP we can call like this so inner class and outer class we can we directly create the object and that object will be the inner class which is HP and we can directly call the H Dot info if this kind of topic is there so definitely we have also the variable exist so the likewise instance function we have also the instance variable okay instance variable and uh we have also the class variable the same time we have also the static variable again this this kind of things we will discuss in the practical way then you’ll understand easily how the instance function class function and static function is working okay so let’s jump on the Jupiter notebook okay here so I’ll create very very very simple uh function here so the topic is instance function class function and um static function example if you creating any kinds of class with normal class uh class name is uh okay uh class name we can say the first class okay first class okay then normal the first class uh the class name is there and you also Define some one Constructor in it and pass this self and here you define it self dot um a is equal to and self do name is equal to you define it and name is hurry okay and Def info I Define it here and simply I Define it here he hurry right self. name I I I’ll just pass it okay self. aray so simply I just create the object let me create the object object name is FC is equal to first class and FC do info so here hey harry so he har is calling it here so I create the class this kind of um uh this kind of function this info function which I Define it s self as a reference it’s passing the references so that we can use the any kinds of variable within a class so this method we are calling the instance method so instance method and I also Define one variable which connect with self so this variable is instance attribute we are calling okay instance attribute or instance variable instance variable we can say inance variable let me create one more uh variable variable name is like um uh College college name okay college name is IIT Bombay I Bombay okay all right and U uh this instance function here you create it instance variable you also create it if I want to call it print and call it here the um instance variable can I just call it so FC do uh name if you’re calling so you can also get the values as hurry so that is also accessible with object as well okay I created the uh one variable is a college name and I want to access it that uh let me just directly write it here so what kind of variable we are calling actually this kind of variable we are calling the um you know class variable class variable we are calling and I’ll just pass it here college name so when I just call this I Bombay is accessible but uh this uh class variable this one is a class variable I if I want to use it any method how can you use the method okay this one is a class variable how can you use the method So Def class okay not class info one I can write it here better I can write it info one and this one in info two okay info one I can just call it here yeah info so again college name is not connected with a self right so in case if I’m writing it here self and uh just just pass it uh you know print college name and here I just pass it simply the self do self. college name so obviously it’s not accessible let me let me just call it FC do info2 okay um that is accessible here it’s accessible it’s not a problem I Bombay is also accessible college name uh but again this kind of variable is a uh class variable because it’s not connected with self self reference is not connected with that here self if you’re forcefully writing it here yes it’s accessible but this function we can’t call it as a um you know instance method yeah instance function we can’t call it if you write it here CLS see LS and then uh then this kind of method is called as a class method okay that is also accessible hope so uh but uh you don’t need to Define it yourself obviously CLS you have to Define it and it’s accessible so CLS if if you’re passing the reference as a CLS then it’s a class method but if you’re passing the reference as a self that is the instance method okay so there is also one more variable and one more mode method we can also use it uh def uh info 3 okay and if you’re not passing anything and make sure that uh we have also you know decorator we can also Define it so for a security purpose so here we can also write it class method okay so we easily uh Define it here decorator is a class method what we are calling we let me also write it out here decorator decorator okay all right so here I’m not passing the CLS I’m not passing the self so this kind of method and and whatever variable I’m just Define it here inside that um I’m I’m defining it a variable here U like um what is name role number yeah role number not a role number and we can say uh the ID student ID which is maybe the confidential student ID I’m just Define it here 1 121 09 okay 12109 this is the confidential and it should not be accessible outside okay and when you just run it you’ll getting the error not getting the error because I didn’t call it so fc. info3 when I just call it is getting the error like saying that take zero positional argument but one was given because because whenever you creating any kinds of method that automatically expecting that it should be either CLS or a self but here I’m not passing anything okay so that is the reason it’s making that here the take zero positional argument but one was given okay so uh one was given that this kind of error will coming definitely will come so how to overcome this kind of problems so this kind of method is called as a static method this kind of method is called a static method there is no CLS there is no self but how to uh you know solve this problem how to create it so there is a decorator you have to Define it here static method and when you just Define it then to not create any kinds of issues and this variable uh student ID if I want to call it static variable okay fc. student ID so that is not accessible there is no attribute because it’s defined in the static method and and it’s not passing the reference with self and uh this class variable that was available in the outside of that that is a global variable and Global variable for that particular class but here you can’t you can’t call it so where you you can use this kind of um method so simply I can just write it here this is uh my my student ID is student ID when I just pass it and and and showing that hope so is showing that yeah okay okay here is showing that uh student ID my student ID is this one okay and this variable we call calling as a uh static variable hope you understand this this all the method and function this one is a class variable and then class method we have we have a instance variable able we have a instance method we have is a static variable we have a static method we have okay so now it’s done and uh you please refer the Jupiter notebook uh if you don’t want to watch all the videos uh you know complete videos just refer the Jupiter notebook run it and try to understand but you face any issues go back to the video and check it where you’re stacking exactly and now we reach the topic of encapsulation we already covered the many topics like um you know the object class polymorphism inheritance okay so now we we have to discuss about encapsulation so encapsulation is really very very important for a security purpose hiding the information so let’s first discuss about the definition here so this one is saying that this put a restriction on accessing variable and Method directly can prevent The Accidental modification of the data to prevent The Accidental changes an object variable can be only be changed by an object method so those type of variable we are calling the private variable so this is the normal definition we will discuss about in a practical implementation as well so you can just imagine that you have a capsule inside a cap you know medicine capsule so whatever information is whatever uh ingredient is there so we can’t see that that is the hidden but we can see the medicine so likewise here we have hidden information we have important information like a method and variable which is available in the class and we can’t directly uh you know we can easily access the method and variable so we provide some restrictions so that the people cannot be accessed directly so there is the multiple way to protect it so we have a topic is called as access modifier so there is a three access modifier is available public protected and private okay so when you’re talking about how uh public protected private is working so before let’s understand that ke how we can access any kinds of method and variable see there is uh some access attribute is available so if you just use this uh get attribute has attribute set attribute so you have a you know you have opportunity you have option to you know get the any kinds of variable or method easily okay with the help of objects obviously and we have also the one more option is available building uh class attribute we can see all kinds of method and variables we can see that so we just try to protect the method and variable so we have access modifier so there is there is a restriction is providing this protect and private so what kind of restriction they are providing so we need talking about the first one is a public member the public member uh kind of variable a variable which is the publicly so the public member of a class let me just take the annotation yeah public member of a class are variable are available to everyone anybody can easily access it so they can access from outside of the class and they can and also other classes too so there is no any restriction for the public public member like whatever whatever variables and Method we have created that is the public member previously what we created that was a public member protected member is providing some restriction there so you can see here the protected member are those members of the class that cannot be accessed outside of the class but can be access from within the class and its subclasses so it’s providing the uh some restriction but not the entire restriction right it you can access it you can access it within the class but outside of the class you can’t access it but when you’re talking about the last one which is a private member so a private member of a class are only accessible within the class even sub classes can also not be accessible so when I just summarize it everything let’s understand the simple way the summary of uh the public protected and private public member Public Access modifier can be accessed with the same class same packages even sub classes and other packages as well so when you’re talking about the protected so protected cannot be access with to other packages but it can be easily accessed with a sub packages sub uh sub classes and same classes as well private access modifier a private member can be accesses within a class only it cannot be accessed from the any other packages or same packages or or any other classes so we already discussed in the last video is that how can we make the um you know static method and how can we make the class method that is the way where we can just uh you know protect our our methods and and some variables so there is also one more topic is called as uh private variables that I’ll I’ll discuss in the practical way let me jump on the Practical implementation to discuss about that inbu attributes the last video we discuss about this instance function instance uh class function and static function so here uh we discuss in the details way and just try to access it some some variables and Method so you can see here when I just use it the object the object here FC FC is the object so when I just use this fscore uncore the dict uncore uncore obviously I have to use the dot do dict you can see here so whatever variable is present here the variable is uh the name actually the instance variable is showing only it’s not showing any kinds of uh the class variable so that is also here you can say it’s protected so so kind of the public private and protected is the category to achieve that category we have a different different uh topic is available so here uh so you can say the class variable class method and static variable static method is also one of the way to achieve the en encapsulation so you can see here when I just use the dict so here uh any any college name is not showing it’s showing only the name right so we have also I also Define some uh documentation so with the help of FC dot FC doore uncore yeah so we can also see the documentation as well so with the help of object we can easily find it out you know other things we can easily access it any kinds of documentation any variables or anything here so like I want to find it out what is the is it uh you know the main module is there or any other module is also there so underscore uncore module you can also check it okay sorry it’s not a DF it’s FC doore module so you can also say check that so I’m working with the same files that’s why it’s showing that U main is here I can also check that the classes as well FC doore class so yes it’s showing that my class name is a first class with the help of object I can find it out anything easier right so I can also check that uh you know there is the variable name is an variable name is name okay variable name is a name okay so I can also find it out has attribute is that attribute is available or not so object I have to Define it FC and name I’ll just pass it it’s saying that yes that attribute is available so I can find it out that variable get attribute I can just use it and pass the values as FC and uh uh what is the actual values of the name is showing that hurry so so you can see here so with the help of object I can find it out any information that I want to protect it okay so like uh a set attribute I can Define it set attribute so outside of the U class with the help of object I can also create one variables instance variable FC and I can Define it here uh any any variable name is like a ro number which is not there hope so which is not there uh yes there is no any role number yeah role number kind of variable is not there so I can make it role number and and Define it the role number is a one 12 one okay so I I set the one variable when I just check that the FC FC doore dict you can see here there is two variable is present previously it was only hurry now the role number is also present right so and and I can also delete it so FC dot FC sorry Del Del attribute delete attribute I just want to remove the FC have to pass it and just pass the role number okay and now it’s deleted hope so uh DF is not defined it’s FC and the next time when I just check this here so it’s showing only hurry it’s not showing other things so this way we can easily access any kinds of uh variables any kinds of methods we can easily access it in a continuation of encapsulation we we discuss about access mod fire where we discuss a public member we discuss a protected member we discuss the private member as well so here we discuss about a private variables how we can make it suppose if you have a class class name is uh College okay college and I Define The Constructor and here I Define the name is equal to uh Rahul so this this is the variable name that variable you can say is the instance variable okay so instead of name I’ll just use a self. name so that I can easily access it within a class and uh create a object object name is like um you know C is equal to college and when I just try to access it like a c do name so you can easily access it which is Rahul and here I just want to write it uh create one um object self dot college ID okay college ID I just want to write it IIT Bay 001 56 suppose this is the college ID is there and uh when I just try to access it the college ID we can easily access it right C do college ID so you can easily access it but what happened uh okay what happened if in case if I’m just writing here the double underscore so what will be happening you can’t access it here is showing that the college ID is uh the college object no attribute of college ID let me also use it under double underscore here still you can’t access it so that means this kind of Vari uh in case if you’re using the two underscore before the any variable you can’t access it but normally if you’re writing any variable a is equal to 5 it’s it can be accessible and print a yeah and if you just using a double underscore a and here if you’re using the double underscore a so that is also accessible here is not a issue but if you’re doing the same thing in your object oriented so it’s become a private variable private variable so private variable have a only only one way to find it out only one way to access that kind of variables which is you have to call the college so with the help of object you can’t access it so here when I just try to access only the name so you can easily access it but if I want to access the C doore uncore college ID so you can’t so the time you have to call the object object name is a college underscore College you have to write it then you can access it so the private variable cannot be accessed directly so again the encapsulation is the way encapsulation is is a techniques where we have a different different topic is available like private variable static method and static variable so that that topic will help you to achieve the encapsulation because in Absolution is a techniques to protect our variable and methods so let’s let’s discuss about the how data abstraction is working data abstraction and encapsulation are synonyms as data abstraction okay so you can just understand with this images so encapsulation is also protecting the method as a variable but abstraction is providing the complete restriction so that you can’t enter it so to re to reach abstraction we need need encapsulation so that means first you have to protect the variable as a method and then you can provide the complete Shield right so just abstraction is is totally give the Restriction okay so so here is the definition is also there let’s let me just read it so that you’ll get a better idea and after that definitely I will discuss about the Practical implementation substraction is used to hide the internal details and show only the functionalities abstracting something abstracting something means to give the names to things so that the name capture the basic idea of what a function or whole program does is give the just basic idea okay to achieve the abstraction so there is a two way so an abstraction abstract class can have both the normal method and Abstract method both can be present an abstract method yeah we cannot create an object of abstract class so how to achieve that abstraction let’s discuss about it so data abstraction let me just create uh the yeah heading data abstraction okay so data abstraction um let me create one a class the class name let me just write it here a computer okay computer and yeah inside a computer let me just Define one uh you know one method normal method is a processing okay and self is very very important and just write it the normal statement anything uh just pass okay so this is not abstract class or abstract method it’s not here so when we can have a abstract method normally whatever you writing here okay whatever you are writing here um print this is computer class okay and I can also write the object C is equal to computer so when you just uh call it C do processing and you can easily access it so now let me just create this this class as a abstract class so you have to import from ABC abstract Blaze class import uh let me just take the ABC Capital so which is the main class is there and Abstract method as well abstract method abstract method yeah so here I will just inherit the ABC so now now the computer become the abstract method so when I just here the abstract method is available okay and uh this class this uh computer become the abstract class but if I want to make the method so I have to use the decorator so abstract method so here so when you just make so when you just make this um processing as a abstract method and uh your class become become the completely abstract class so you here is saying that cannot Institute abstract class computer with abstract method processing you cannot use it okay so you can’t create object of any abstract class if when when we are calling the abstract class if you inherit from the ab ABC abstract Base Class and if you have a method which is the abstract method so that time we are we are calling it’s the abstract class an abstract method so if I want to just create any um any other you know I want to use it this is computer class I I just want to use it so I can also create a different um um different classes here let me just create a laptop okay simply laptop and this time I will inherit the computer so computer is inherit the abstract Base Class and laptop is inherit the computer and and simple I’ll just write it here the processing anything I can just use it now here what will be happen so here is kind of um overriding so because I just inherited that so overriding here just using self I’m just using it here and uh whatever things is there I’ll just pass it is high so instead of creating the object of a computer I will just create the object of a laptop so let me just comment it here lap L is equal to laptop L do processing when I just use the processing you’ll get high because it’s become completely inherited if it’s completely inherited the previous one will not be used okay but in case instead of processing if you have a processing one and if you want to inherit the then again is facing the same problem you cannot okay you cannot even not only the um not only the calling the methods so if you’re still running so you cannot create the object of the class the laptop class as well because laptop is inherited the a computer computer is a completely abstract class right because it’s inherited the abstract Base Class so here you cannot use it until unless you’re not overriding the abstract method so here I’m just overriding the abstract method now I can create object I can also call any method as well so this is the way to deal with any abstract class so again if you have any kinds of U uh method which you want to protect it you can just use abstract me abstract method with ABC abstract Base Class finally we reach the last topic of this entire python series that is multi- threading multi-threading is very very very important for a software development even um uh you’ll find it out the separate job for uh you know for multi- threading so even when you’re entering uh the multi- threading let’s first discuss about the multitasking how exactly it’s working because dayto day day-to-day life when you’re using the computer so different different task we are just doing it let’s say for example I’m just doing a task is a word processing and and sending some emails and doing web browser and uh our in virus is running so that entire thing is running on the operating system right and that operting system is is is on a CPU course so even so multi-threading is not only the software topic uh like if you are a programmer you should know that it’s not like that if if you’re using a computer the multitasking and multi- threading is running inside your computer so let’s let me first show you how exactly the multi trading and multitasking is running in your computer you can just go to the taskbar you uh shortcut keys control alt delete you’ll find it out the taskbar go there the taskbar will open here so in your computer it will be open and just go to the performance and let me just maximize it yeah you can see here uh yeah you can see I’m just running the 312 process with the threads so what exactly the threads thread is nothing but a lightweight process so I I’ll discuss in details let first understand that like if I’m just running the multiple process my computer is running the 312 process which handles the 177,000 1 lakh 73589 right and that how much core is there 10 core so core is nothing but how your whatever process you’re running is the Distributing in the different different core that is CPU core okay and every process have a different different threads that means small process is there inside one process for example you can go to the processes 312 processes running go to the processes you’ll find it out which 312 processes there so five is ongoing processes there five apps is running I just open the uh PowerPoint I open the taskbar WhatsApp Zoom is running so much things running is here and and another process is also running the background process because sometime you confuse that here is the 312 process where exactly is that see some background process is also there and other processes also consuming right so after uh the entire process is 312 is showing it here so let’s understand it like how trades is working threads is nothing but just a small process of the particular process it’s confusing let me show you how exactly is working let’s say for example I choose the uh normal things is is game okay in the game I choose the I just open one game so game is a one process okay game is one process but inside that the multiple process is running that is consu that is producing the sound that is Graphics that is U when a player is uh you know it’s a different different opponent is there the multiple prer is playing the games so kind of like the multiple Pro multiple small small processes running inside the game app your game process so simple here so what exactly the multitasking multitasking refer to the ability of operating system to perform a different task at the same time because here in the operating system I’m just running the multiple process at the same time right so as I said that uh when you’re going for a job so you’ll find it out the multi- threading is also very much required if you are entering the software development that can be the web development that can be the application development with a python not only the python if you are going with a Java that time is also required the multi-threading right so you can also search it on no.com I just took the screenshot here but yeah lots of job opening is there for multi-threading that is also required and uh the interviewer is asking the question right yeah so here I took the example is a word processor okay word processor one one example I just taking it here inside that so Graphics is there and responding to keystroke and grammatical check that is a small small process which is there inside a word processor right so that small small processor that small small process is called as a dats simple word what exactly the threads so thread is nothing but a lightweight process thread is a lightweight process which is independently flow up execution that means there is no dependent that when uh Graphics will complete then the cas keystroke will run no there is independently running so whenever you making the application so threading is playing the very very important role because we have to we have to achieve the independent iny right so here so there are two types of multitasking in operating system that is a process best and thir best right so what is a process best because the multiple threats running on the operating system simultaneously for example for example is listening the song and playing the game is is two different process running in the operating system but when you’re talking about the threats so thread is a single process consisting of the separate task right for example a FIFA game is a consisting of the multiple threads so one game is a consisting of multiple threads is there so now the question is what is threat even I already explain that thread is nothing but a lightweight process so inside the threads in inside inside the one process the multiple threats is there is this example is mentioned there so the question is where we can use it what is the purpose of thread when we required the threads is there so threads when we have a multiple task need to achieve you have multiple task and you want to independently running it so task don’t have interdependency right if I’m running the one particular function there is uh four function is there fun one and fun two and fun three and fun four okay so I so python is a procedural programming language and functional as well and objectoriented as well but usually is following the top to B bottom approach when the fun if in case if I call the first function second function third function fourth function accordingly it will run but there is no any relation between the function one to function two it can be independently run so in the time we required a mult the training so that is the mean of interdependency it should not be any kinds of interdependency between the two different function right so there is two way to create the threads in the Python programming language the first one is without creating a class directly with a function we can create it and with a class we can achieve the threads okay so there is the four things which is very very important to know about that how to perform the multi- threading task so run there is run method which is which method is entry point of the threads and start method which is start the thread when you call the run method it will start the trade and join method it will be uh wait for Threads to terminate it and is alive will check that your thread is still alive or not and get name get the get name will return the name of the threads so this five method will help you to perform the entire thre operation uh let’s take example suppose I have a two task the task number one read um read data from database and there is a 10 data I have to read it right and the second task I have um read um PDF file okay that is also 10 PDF I have so there is a two different task and uh this one is taking every every database every data is taking a 0.5 second that means it will taking okay 0.5 second one task will take 0.5 second one task will take so it will taking a 5 Second okay all right and the second one second one read the PDF so 0.3 second is taking so it will taking completely a 3 second okay so I’ll try to optimize it in this Pro this problem right so the complete if you if you’re running the entire task it will taking the completely 8 second I’ll try to reduce it to make it around U uh 5 Second okay let me take the four and this will be 4 second so total will be total will be 9 second great so let’s do the do the Practical implementation here def I’ll create one one uh function def um read data okay read data and simple I’ll just create of follow for I in range and yeah the 10 data I have to read it and print the normal statement read the data from database okay and uh I + 1 because it will start from zero right and let me also take the time import import time or I can yep and every time it will take time do slip 0.5 second 0.5 second I’m uh so every process is will taking a 0.5 second and then def read PDF for I in range 10 I will pass and time do sleep and 0.4 second and print the statement um read the data from uh PDF okay read the data from PDF and and then I plus one as well because it will start from zero all right great so yep I’ll just print it here start time strd start time is equal to uh time dot time I think time do time is there let me let me just print it time do time yeah so time. time it will starting time it will take and uh mhm start time and at the end when I just call it I’ll just call this function rate data and rate PDF okay and I will take it here the end time is equal to time. time time. time and uh process took time process time I can make it here end time minus start time okay so it will start the process so first it read the entire data from database and then uh the PDF will start and here it’s taking a 9 second why it’s taking the 9 second the reason behind that the reason behind that because the first one took the 5 Second and second one took the 4 second that is the reason it’s more than 9 second is taken here so how can I reduce it this time so we can use the multi-threading to reduce this particular time is here so there is a librar is called multi- threading from multi threading multi threading import I’m taking a everything like even I required here the thread so I’m taking the Trad here oh sorry uh better I can just take this libraries in the outside so that it will be oh sorry uh I can undo it yeah undo delete yeah here I can pass my library okay multi-threading spelling is wrong M ready okay it’s not a multi- Threading uh sorry it’s a Threading only sorry yeah threading import thread So currently whatever process I have it’s not inside the thread so I’ll try to make it the inside thread so so this one is not required this one is just taking the time this one I’ll just make it comment and I’ll make it a thread so T1 thread so inside a thread because there is no any class so you have to decide the target what is the target the target is uh read data the second one is T2 is equal to thread what is the target the target is read PDF and uh the simple one let’s start a T1 dot start uh start the U uh thread here t1. start and then t2. start when I start this two different threads so here the threads will run independently there is no relation between the read PDF and read data so the same time your data from the DAT reading data from database and reading the data from PDF will start the same time so you can save a lots of time is here you can sa then tar 4 second let me just run it oh what what’s the issues spelling is wrong seriously mhm d h r e a d hey it’s it’s correct oh okay spelling is wrong yeah sorry yeah so it started the time is started here the process time okay uh the problem is here it’s attached with um uh the completely this time is attached with our threads okay I have to also explain one more thing is here so there is always one thread is always active which called as a men thread so because of this because of this threading so this one is also considered as a Threading this one is also independently run this file right this is independently run this file in that situation what I have to do I have to just join it t1. join t2. join so what happen is here so T1 and T2 is joined it’s not joined with the men threate right so here this this entire this process this this two Lines line number 27 and 28 is not joined with T1 and T2 so T1 and T2 is running the independently so that is the reason you can see here it’s reading the PDF then database PDF database and sometimes the PDF two time as well the reason is taking only 2 second and the entire process is ending with 5 Second only previously it took a 9 second I save a 4 second so that means if you have the big process if you have a big process so and and imagine that imagine that uh currently I have only two process you have a 15 process and all the 15 process have independently running so what which process is taking more time inside that the other process can also be finished it so multi- threading is saving a lots of memory lots of time so that’s why it’s very very important for a software development so usually the software we are making with class class and object read data from database that it will take 10 second and the second one read PDF from read data from PDF yeah we can say read PDF files that is taking a 4 second there is a 10 files and every files is taking 0.4 second the total time is 9 second okay so I’ll try to create with the class here the multi-threading so simple uh class name is class of read data and uh make sure that if you’re if you’re using the multi trading so you have to inherit the thread so let me just use the prom threading import thread and from time UT C okay great so I have to import thread here okay all right and inside that you have to create a function yeah we can say method def run method okay run method self is very very important okay and after that give me a minute after that just we have to run the file for I in range and the 10 times and uh let’s apply the slip 0.5 second right this normal statement okay read data from database database right this is one threade I just created and the second one is class read PDF and thread colon def run and pass the self is here for I in range pass the values is 10 okay the same thing I’ll just use it here slip 0.4 second and print the statement read PDF data that’s PDF data all right and how it will be run just call create object of that particular thread T1 because the every class is already become the thread because it inherited from thread class is equal to read data okay so if you’re not using this a threat inheritance let me just show you okay let me just show you I’m not using inheritance of the thread and uh let’s create the object T2 do T2 is equal to read PDF so when I just run it and let’s run this file here T1 dot T1 dot run okay and t2. run and uh just just normally Define it here the timing okay start start time is equal to time dot okay time sleep and time let me just take both time and yeah just time you can just take it and uh at the last time this end time okay that is the end time and uh just print it here process time that is like uh end time and time minus start time okay so it will it will tell you like how much time it took to complete the entire process we know that here it will take uh the 9 second because the 5c first read data will take and the second one 4 second will take so yeah it’s took the 9 second yeah let me also just Define it the number which file is reading I + 1 because it’s starting from the zero so that’s why I’m just mentioning here the I + 1 great so let’s apply the inheritances here let’s apply the threading with inheritance uh um concept so we just inherit the thread and let me also inherit the thread so if you use the method is a run and uh you don’t need to call the run so now the entire process has become the complete thread right so this this entire classes become the thread this this one is a thread and this one is a thread so now I want to run it then t1. start that’s it t2. start that’s it now when you just start it the process will start again yeah so this one uh this print statement this is completely a separate threats that is the reason that is also being independent so that is it’s running first so let’s make it dependent there is if I’m asking that how many threads is running is here so there is a three thread is running the first one is read data second one is yeah we can say T1 T2 and the third one is men thread so men is always there so all menth is being independent so making the T1 and T2 is a dependent you can make it t1. join and t2. join so now you both will join and the men threate is independent so the line number 27 will be running dependently right when the T1 and T2 will finish then 20 line number 27 will run then you’ll find it out how much time it took it here the last time it took 9 second now it’s taking only a 5 Second so this is the beauty of multi-threading so let’s also discuss the other things um how many threats is there we can also check it and U uh yep so if if I’m just printing it here in in the next line I can just directly print it here print uh like a T1 do um um I can check it like is alive or not uh we can we can normally check it so it will tell you yes it’s it’s false because uh the process is end so it will tell you yes it’s a false so if you’re running inside that in inside that um uh threads like here if if I’m just after start if I’m just running so definitely give the answer is the the threads is running or not the T1 thread check all right 31 thread check it will check the true because the threads is running right so with the help of is alive we can check it the threads is running or not so we can also check the other things like um uh the active count okay so here when I just check it in between anywhere we can check check it here um number of threads we can check it number of thread so we can check it so simply we can just pass it here active count there is a method is called as active count okay so active count when I just run it it will tell you the number of threads is eight is running yeah like number threat is 8 is running because the complete active count is 8 is here okay and uh so the same time like here uh what is the thread name is I can also check that what is the exactly the thread name is here so at the same time I can also check it here the current thread dot get name okay current thread. getet name so we can also check it like which thread is running that uh particular line and here you can also check it right so when I just run it it will tell you okay so it’s showing that 32 3T like the thread number is showing that and the last one is a men thread so now here some somewhere like number of threads is there because the entire thread is not stopped that is the reason it’s showing that is a eight so when I just checking the outside how many threads is running outside here so it’s showing six so the six is running the two is not considered here so hope you understand how exactly this working right so active alive we can check that that particular thread is running or not how many uh active thread is there and what exactly the thread name is here you can easily check it with all the methods oh
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
Ben Azadi’s “The World’s Easiest Diet For Visceral Fat Reduction In 14 Days” outlines a seven-step protocol to reduce harmful belly fat. The core principles involve lowering insulin through carbohydrate restriction and prioritizing protein and healthy fats. Additional recommendations include eliminating snacking, incorporating sprints and daily walking (especially post-meal), avoiding alcohol, practicing intermittent fasting with an 18/6 schedule, and optimizing for 90 minutes of deep sleep nightly. The text also addresses the role of stress and protein intake in fat loss and details methods for measuring visceral fat, emphasizing MRI scans for visualization. Ultimately, the source provides actionable lifestyle changes for rapid visceral fat reduction and improved metabolic health.
The World’s Easiest Diet For Visceral Fat Reduction: A Study Guide
Quiz
What is visceral fat and why is it considered dangerous?
According to the source, which macronutrient has the most significant impact on insulin levels? Explain why this is relevant to visceral fat storage.
Describe the first step of the recommended protocol for reducing visceral fat. Provide a few examples of foods to avoid and foods to include.
Why is snacking discouraged in this dietary approach? Explain the analogy used to illustrate this point.
What is the suggested protocol for sprinting, and how does this type of exercise help in reducing visceral fat?
Explain why alcohol consumption is discouraged for those trying to lose visceral fat, according to the source.
How does walking, especially after meals, contribute to visceral fat reduction? Briefly describe the study mentioned to support this.
Outline the 18:6 intermittent fasting schedule recommended in the source and explain the proposed benefits for visceral fat loss.
Why is deep sleep considered important for burning visceral fat? List three scientifically proven tips provided to improve deep sleep.
According to the interview with JJ Virgin, why is prioritizing protein intake beneficial for reducing body fat, including visceral fat?
Answer Key
Visceral fat is the fat stored around the abdominal organs, often referred to as belly fat. It is dangerous because it applies pressure to vital organs like the heart, kidneys, liver, and pancreas, contributing to chronic diseases such as fatty liver disease, obesity, cancer, and heart disease.
Carbohydrates have the most significant impact on insulin levels. When carbohydrates are consumed, they cause the highest blood insulin response compared to protein (moderate response) and fat (minimal impact). Elevated insulin is the primary hormone that signals the body to store visceral fat.
The first step is to lower the hormone insulin by swapping carbohydrates for protein and fat. Foods to avoid include oats, oatmeal, cereal, bread, grains, fruit, fruit juices, quinoa, rice, potatoes, sweet potatoes, and legumes. Foods to include are cauliflower rice, squash rice, cabbage rice, eggs, red meat, wild-caught salmon, poultry, and goat/sheep dairy.
Snacking raises glucose and subsequently insulin levels, even if the snacks are considered healthy. This disrupts the metabolism and prevents the body from burning stored visceral fat. The analogy used compares snacking every few hours to someone constantly banging on your office door, disrupting your productive workflow.
The sprinting protocol involves a 20-second all-out effort sprint followed by 90 seconds of rest, repeated for three total rounds, three times per week. High-intensity interval training like sprinting activates hormones such as human growth hormone, making the metabolism more efficient at using stored fat for energy after glycogen stores are depleted.
Alcohol is considered a poison and a toxin that the liver prioritizes metabolizing before fat. This slows down fat burning. Additionally, alcohol stimulates appetite, decreases testosterone levels (which can hinder fat loss), and can increase estrogen levels (linked to abdominal fat storage).
Walking after meals helps to blunt the spike in blood sugar that occurs after eating, even with a lower carbohydrate intake. This results in less insulin being produced, allowing the body to enter a fat-burning state faster. A study showed that a 30-minute brisk walk after meals improved the glycemic response regardless of the meal’s macronutrient composition.
The 18:6 intermittent fasting schedule involves fasting for 18 hours a day and having a 6-hour eating window (e.g., 12:00 p.m. to 6:00 p.m.). This schedule is proposed to lower insulin levels, increase human growth hormone, reduce insulin resistance, boost metabolism, and promote overall hormonal balance, all of which can contribute to visceral fat loss.
Deep sleep is where most fat-burning hormones are activated, and the body taps into stored fat for energy. Three tips for better deep sleep are drinking banana tea, keeping the bedroom cold (around 65°F), and ensuring the bedroom is completely dark (using blackout curtains or a sleep mask).
Prioritizing protein intake is beneficial because protein is more metabolically costly to digest and assimilate compared to fats and carbohydrates (having a higher thermic effect). Eating protein first can also lead to feeling fuller for longer, reducing overall calorie intake and cravings, which are crucial for achieving a caloric deficit needed for fat loss.
Essay Format Questions
Discuss the interconnectedness of diet and hormones, specifically focusing on the role of insulin and cortisol in visceral fat storage and reduction as described in the source.
Critically evaluate the seven-step protocol presented for visceral fat reduction. Which steps do you find most compelling and why? Are there any potential challenges or limitations to following this plan for the average individual?
Compare and contrast the different types of exercise discussed in the source (sprinting and walking) in terms of their mechanisms for promoting visceral fat loss and their practical implications for implementation.
Analyze the importance of lifestyle factors beyond diet and exercise, such as sleep and stress management, in the context of the source’s recommendations for reducing visceral fat.
Based on the information provided, synthesize a comprehensive strategy for an individual aiming to significantly reduce their visceral fat within a few months. Include specific dietary changes, exercise recommendations, and lifestyle adjustments.
Glossary of Key Terms
Visceral Fat: Body fat that is stored within the abdominal cavity and surrounds vital organs such as the liver, intestines, and stomach.
Insulin: A hormone produced by the pancreas that regulates blood sugar levels. It also signals the body to store excess glucose as fat.
Cortisol: A steroid hormone produced by the adrenal glands in response to stress. Chronically elevated levels can contribute to increased visceral fat storage.
Macronutrients: The three main categories of nutrients that the body needs in large amounts: carbohydrates, proteins, and fats.
Glycogen: The stored form of glucose, primarily in the liver and muscles, which the body can use for energy.
High-Intensity Interval Training (HIIT): A form of exercise that involves short bursts of intense activity followed by periods of rest or low-intensity activity.
Postprandial: Occurring after a meal.
Glycemic Response: The effect that carbohydrates in food have on blood sugar levels.
Intermittent Fasting: An eating pattern that cycles between periods of eating and voluntary fasting on a regular schedule.
Autophagy: A natural cellular “clean-up” process where the body removes damaged or unnecessary components.
Human Growth Hormone (HGH): A hormone produced by the pituitary gland that plays a role in growth, metabolism, and fat burning.
Insulin Resistance: A condition in which the body’s cells become less responsive to insulin, leading to higher blood sugar levels.
Neurodegenerative Diseases: Conditions that progressively damage or kill nerve cells in the brain and spinal cord.
Leptin: A hormone produced by fat cells that helps regulate appetite and energy balance, often referred to as the satiety hormone.
Satiety: The feeling of fullness and satisfaction after eating.
Deep Sleep (Delta Sleep): A stage of sleep characterized by slow brain wave activity, during which the body repairs tissues, builds bone and muscle, and releases important hormones for fat burning.
Nitric Oxide: A molecule that helps blood vessels relax and widen, improving blood flow.
Vaso Dilation: The widening of blood vessels.
Oxytocin: A hormone often associated with bonding and social interaction, which can help lower cortisol levels.
Thermogenic Effect (or Thermic Effect of Food): The energy expenditure of the body above basal metabolic rate due to the cost of processing food for use and storage. Protein has a higher thermic effect than fats or carbohydrates.
DEXA Scan (Dual-energy X-ray Absorptiometry): A type of medical imaging scan that uses low levels of X-rays to measure bone density and body composition, including fat mass.
MRI (Magnetic Resonance Imaging): A medical imaging technique that uses strong magnetic fields and radio waves to create detailed images of the organs and tissues in the body, allowing for the visualization of visceral fat.
CT Scan (Computed Tomography Scan): A medical imaging technique that uses X-rays and computer processing to create cross-sectional images of the body, which can also be used to assess visceral fat, though it involves radiation exposure.
Myosteatosis: The infiltration of fat into skeletal muscle tissue.
Briefing Document: The World’s Easiest Diet For Visceral Fat Reduction
Source: Excerpts from “01.pdf” by Ben Azadi
Date: October 26, 2023 (Based on the provided context)
Author/Presenter: Ben Azadi (Keto Kamp)
Main Theme: This document outlines a 7-step protocol presented by Ben Azadi for effectively reducing visceral fat (the dangerous belly fat surrounding organs) in less than 14 days. The protocol focuses on dietary changes, lifestyle adjustments, and exercise to lower insulin levels, activate fat-burning hormones, and improve overall metabolic health. Azadi supports his claims with his personal transformation story and insights from health experts and research.
Key Ideas and Facts:
1. Lower Insulin Levels Through Dietary Changes:
Visceral fat storage is primarily driven by the hormone insulin. “when this hormone insulin is elevated a ton of visceral fat gets stored around your belly.”
Carbohydrates cause the highest insulin spike compared to protein (moderate) and fat (minimal). “when you eat carbohydrates you can see it creates the highest blood insulin response protein is number two but it’s a moderate insulin response and fat barely touches the dial on insulin.”
The first step is to swap carbohydrates for protein and fat to lower insulin and enable fat burning. “the first step here in your protocol is to swap carbohydrates for protein and fat.”
Common “healthy” foods like açai bowls (99g sugar), Lucky Charms (60g sugar in two servings), oatmeal (52g sugar in two servings), and orange juice (52g sugar in two cups) are high in sugar and cause significant insulin spikes.
Foods to remove include oats, oatmeal, all cereals, bread, grains, fruit and fruit juices, quinoa, white and brown rice, potatoes, sweet potatoes, and all legumes.
Foods to replace them with include cauliflower rice, squash rice, cabbage rice, eggs (whole), red meat (beef, lamb), wild-caught salmon, organic poultry (chicken, turkey), goat and sheep dairy (preferred over cow dairy due to higher MCT content), and greens (arugula, broccoli, Brussels sprouts, cauliflower).
Aim for under 50 grams of total carbohydrates per day to facilitate the metabolic switch to fat burning.
2. Stop Snacking Between Meals:
Every time you snack, you raise glucose and insulin levels, hindering fat burning. “every time you snack you raise glucose and then insulin even if it’s a healthy snack.”
The average American eats 17 to 23 times per day due to grazing.
Snacking disrupts the metabolic “fat-burning workflow.”
The recommendation is to start with three meals a day and gradually work towards intermittent fasting.
Sprinting is the “best exercise you can do to blast melt visceral fat.”
HIIT activates hormones like human growth hormone, making metabolism more efficient at using stored fat for energy.
Protocol: 20-second all-out sprint followed by 90 seconds of rest, repeated for three total rounds, three times per week (5-7 minutes total).
4. Eliminate or Limit Alcohol Consumption:
Alcohol is a “poison” and a toxin that the liver prioritizes metabolizing over fat burning.
Alcohol slows fat burning and can stimulate appetite, decrease testosterone, and increase estrogen levels (especially beer, linked to “beer belly”).
Recommendation: No alcohol. Opt for unsweetened mocktails or sparkling water with lemon.
5. Increase Daily Walking, Especially After Meals:
Aim for at least 7,000 steps daily, with 10,000 being even better.
Walking after meals helps to blunt blood sugar spikes and reduces the amount of insulin needed. “by going for a walk you blunt this big spike in blood sugars and you allow less insulin to become produced meaning you get into a fat burning State faster.”
A study showed that a 30-minute brisk walk after meals improved the glycemic response, even after high-carbohydrate meals. “although higher glucose levels were observed with High carbohydrate meal our finding show that a 30 minute post prandial meaning after eating brisk walk session improves the glycemic response after meals huge.”
Mike Mutzel, a fat loss expert, recommends breaking walks into “exercise snacks” of 2,500-3,000 steps interspersed throughout the day, which is more effective than one long walk.
Research suggests that walking at least 8,000 steps per day helps prevent metabolic deterioration and improves fat utilization. A low step count (around 2,600) resulted in an exaggerated post-meal triglyceride level and a 30% reduction in fat oxidation compared to a high step count (around 8,500).
Walking after a high-carb meal can significantly reduce glucose levels. Mike Mutzel experienced his glucose dropping from 185 to 85 mg/dL after a one-mile walk following a high-carb vegan meal.
Walking stimulates muscles to absorb glucose, reducing the need for excessive insulin.
Blue Zone research suggests that movement and recreational activity play a significant role in longevity, alongside diet.
6. Practice Intermittent Fasting (18/6 Schedule):
Intermittent fasting offers numerous benefits, including protection against neurodegenerative diseases (via autophagy), lowered insulin levels, increased human growth hormone (key for fat burning), reduced insulin resistance and blood sugar, reduced heart disease risk and blood pressure, boosted metabolism, potential lifespan extension, reduced inflammation, and improved hormone levels (leptin, testosterone).
The recommended schedule is an 18/6, meaning an 18-hour fasted state (water, electrolytes, supplements, coffee, tea only) and a 6-hour eating window (e.g., 12:00 PM to 6:00 PM) with 2-3 meals.
7. Aim for 90 Minutes of Deep Sleep:
Deep sleep (Delta sleep) is when you burn fat and visceral fat, and fat-burning hormones are activated.
Track deep sleep using devices like Oura Ring, Apple Watch, or Fitbit.
Scientifically proven tips for more deep sleep:
Drink banana tea (boiled banana with peel).
Keep the bedroom cold (around 65°F).
Ensure the bedroom is dark (blackout curtains or sleep mask).
Practice mouth taping to encourage nasal breathing and increase nitric oxide.
Take 400-600 mg of magnesium.
Questions and Answers:
Role of Stress (Cortisol): Cortisol works with insulin to store visceral fat. Chronic high cortisol levels lead to a “cortisol belly.” Managing stress (mental, emotional, physical, chemical) is crucial. Increasing oxytocin (through hugging, laughter, hobbies, gratitude – “vitamin G”) helps lower cortisol.
Protein Intake: Focus on protein intake (ideally 0.7 to 1 gram per pound of ideal body weight) for satiety, increased metabolic cost of digestion, and to support lean muscle mass. JJ Virgin emphasizes eating protein first at meals.
Measuring Visceral Fat:Indirect: Fasting insulin blood test (levels over 10 suggest insulin resistance and visceral fat storage).
Most Accurate: MRI scan of the abdomen. CT scans can also show visceral fat but involve radiation. Dexa scans quantify but don’t visualize visceral fat effectively.
Dr. Shan Omar, a visceral fat expert, emphasizes the visual impact of seeing visceral fat on an MRI as a powerful motivator for change. He notes that radiologists typically don’t report on visceral fat. Fatty infiltration in skeletal muscle often correlates with high visceral fat. Re-testing frequency depends on individual levels and goals, ranging from 3-12 months. Cost of MRI can vary significantly.
Quotes:
“visceral fat is the nasty belly fat around your stomach”
“insulin is the hormone that tells your body to pack on the visceral fat it’s the only hormone in your body that stores fat”
“when insulin is high from eating carbohydrates you’re your fat burning hormones they go and they hide they cannot coexist with insulin”
“sprinting is the best exercise you can do to blast melt visceral fat”
“alcohol is a poison to your body it’s a toxin to your brain”
“walking actually helps you uh trigger the the autophagy mechanisms that are some of the health benefits linked with fasting” (Quote from Mike Mutzel)
“Deep sleep right here this is where you burn fat this is where you burn visceral fat this is where most of your fat burning hormones are activated”
“gratitude is strength training for your soul” (Ben Azadi)
“eat protein first because I have been at too many dinners and heard too many times from women that they get too full to eat their protein” (Quote from JJ Virgin)
“MRI is the best way uh to do that and uh it’s uh when when people visualize it I get lots of colorful language the f bomb is dropped all the time” (Quote from Dr. Shan Omar)
Next Steps (Implied):
Follow the 7-step protocol.
Consider checking fasting insulin levels.
If motivated, explore getting an MRI scan to visualize visceral fat.
Check out the Keto Kamp recipes and other resources mentioned.
Watch the recommended video on “10 foods that put you in a fat burning State.”
This briefing document summarizes the core principles and actionable steps presented in Ben Azadi’s guide to reducing visceral fat. The emphasis is on understanding the role of insulin, making strategic dietary changes, incorporating specific types of exercise, prioritizing sleep, and managing stress to achieve rapid fat loss and improved metabolic health.
Visceral Fat: Reduction Through Diet and Lifestyle
Frequently Asked Questions About Visceral Fat Reduction
1. What is visceral fat and why is it dangerous? Visceral fat is the fat stored around your abdominal organs, often referred to as belly fat. It’s different from subcutaneous fat, which lies just beneath the skin. Visceral fat is particularly dangerous because it’s metabolically active, meaning it releases hormones and inflammatory substances that can contribute to chronic diseases such as heart disease, type 2 diabetes, fatty liver disease, obesity, and even certain types of cancer. It puts pressure on vital organs like the heart, kidneys, liver, and pancreas, hindering their proper function.
2. What is the “easiest diet” to reduce visceral fat quickly? The core principle of this diet focuses on lowering the hormone insulin, which is the primary hormone responsible for fat storage, especially visceral fat. The easiest approach involves swapping high-carbohydrate foods for protein and healthy fats. Carbohydrates cause the most significant spike in insulin, followed by protein (a moderate response), while fat has a minimal impact. Therefore, to promote fat burning, especially visceral fat, it’s recommended to drastically reduce or eliminate foods like oats and oatmeal, all cereals, bread and grains, fruit and fruit juices, quinoa, white and brown rice, potatoes and sweet potatoes, and all legumes. Instead, focus on consuming non-starchy vegetables (like cauliflower rice, squash rice, and cabbage rice), whole eggs, red meat (beef and lamb), wild-caught salmon, organic poultry (chicken and turkey), and goat or sheep dairy (or raw, organic, grass-fed cow dairy in moderation). Aim to keep total carbohydrate intake under 50 grams per day to facilitate a metabolic shift towards fat burning.
3. Besides diet, what other lifestyle changes are crucial for blasting visceral fat? Several lifestyle modifications complement dietary changes for effective visceral fat reduction: * Stop Snacking: Frequent snacking, even on healthy foods, elevates glucose and insulin levels, hindering fat burning. Aim for three main meals a day initially and consider progressing to intermittent fasting. * Implement Sprints: High-intensity interval training like sprinting (20 seconds of all-out effort followed by 90 seconds of rest, repeated for 3 rounds, 3 times per week) is highly effective in activating fat-burning hormones like human growth hormone and depleting glycogen stores, forcing the body to utilize stored fat. * Eliminate or Limit Alcohol: Alcohol is a toxin that the liver prioritizes metabolizing, thus slowing down fat burning. It also stimulates appetite, decreases testosterone (important for fat loss), and can increase estrogen levels (linked to abdominal fat). * Increase Daily Walking: Aim for at least 7,000, ideally 10,000 steps per day. Post-meal walks, even for 30 minutes, are particularly beneficial in blunting blood sugar spikes and reducing the need for excessive insulin production. Breaking up walks into 2,500-3,000 step sessions throughout the day can be more effective than one long walk. * Practice Intermittent Fasting (18/6 Schedule): Fasting for 18 hours daily with a 6-hour eating window (e.g., eating between 12 pm and 6 pm) can protect against neurodegenerative diseases, reduce insulin resistance, lower blood sugar and blood pressure, boost metabolism, extend lifespan, reduce inflammation, and optimize hormones like human growth hormone, leptin, and testosterone, all contributing to visceral fat loss. * Prioritize Deep Sleep (90 Minutes): Deep sleep is crucial for fat burning and the activation of fat-burning hormones. Tips to improve deep sleep include drinking banana tea, keeping the bedroom cool (around 65°F) and dark, using mouth tape to encourage nasal breathing, and taking 400-600mg of magnesium.
4. How does stress impact visceral fat accumulation? Stress plays a significant role in visceral fat storage. While insulin is the primary fat-storing hormone, cortisol, the stress hormone, works in conjunction with it. Chronically elevated cortisol levels can lead to increased visceral fat storage, often referred to as a “cortisol belly.” Managing stress through adequate sleep, addressing mental, emotional, physical, and chemical stressors, and increasing oxytocin (the “love hormone”) through actions like hugging, laughing, engaging in hobbies, and practicing gratitude can help combat cortisol and reduce visceral fat.
5. How much protein is recommended to help burn visceral fat? Protein is crucial for fat loss due to its high thermic effect (the energy required to digest and assimilate it), its ability to promote satiety (keeping you feeling full longer), and its role in preserving lean muscle mass during a caloric deficit. A general recommendation is to aim for 0.7 to 1 gram of protein per pound of your ideal body weight. Prioritizing protein intake, especially eating it before other macronutrients, can help manage hunger and cravings, supporting overall calorie control and visceral fat reduction.
6. What are the ways to measure visceral fat? There are both indirect and direct methods to measure visceral fat. * Indirect Method: A fasting insulin blood test can indicate insulin resistance. A fasting insulin level over 10 suggests insulin resistance and likely the presence of excess visceral fat. This is a relatively inexpensive test that can be requested from your doctor. * Direct Methods: The most accurate ways to visualize and quantify visceral fat are through imaging techniques like DEXA scans, CT scans, and MRI scans. While DEXA scans provide a number representing visceral fat, they don’t offer a visual representation. CT scans and MRI scans provide images that clearly show visceral fat (appearing as white on the scans). MRI scans are considered superior due to their higher resolution and lack of radiation. However, it’s important to note that visceral fat is often not routinely reported by radiologists. Visualizing the visceral fat on an MRI or CT scan can have a strong emotional impact, motivating individuals to make necessary lifestyle changes. Software exists that can quantify visceral fat from these scans, though it’s not always necessary as the visual evidence can be powerful. Repeat testing can be done every 3 to 9 months to monitor progress. MRI scan costs can vary significantly by location, so it’s worth shopping around.
7. Can walking really help in losing stubborn belly fat? Yes, walking is a mandatory aspect of a healthy lifestyle and significantly aids in reducing stubborn belly fat. Aiming for around 9,000 steps per day is a good target, with benefits increasing up to 12,000 steps for disease prevention. Breaking up walks into multiple shorter sessions (2,500-3,000 steps each) throughout the day is more effective than one long session. Walking after meals is particularly beneficial for blunting post-meal glucose spikes, reducing the need for high insulin levels, and promoting fat burning. Research shows that even a brisk 15-20 minute walk after a higher-carb meal can significantly lower glucose levels. Furthermore, consistent walking improves the body’s ability to oxidize fat.
8. What is the connection between deep sleep and visceral fat loss? Deep sleep is a critical phase of sleep where the majority of fat-burning hormones are activated, allowing the body to tap into stored fat for energy, including visceral fat. Aiming for approximately 90 minutes of deep sleep each night can significantly accelerate visceral fat reduction. Strategies to enhance deep sleep, such as maintaining a cool and dark bedroom, practicing nasal breathing through mouth taping, and ensuring adequate magnesium intake, can optimize this fat-burning process during sleep.
Burning Visceral Fat: A Seven-Step Protocol
Visceral fat is described as the nasty belly fat around your stomach. It’s problematic because it applies pressure to vital organs like your heart, kidneys, liver, and pancreas, potentially leading to chronic diseases such as fatty liver disease, obesity, cancer, and heart disease.
According to Ben Azadi, the easiest diet to follow to reduce visceral fat in less than 14 days involves a seven-step protocol.
Here are the seven steps for burning visceral fat outlined in the source:
Lower Insulin: The primary hormone that signals fat storage, particularly visceral fat, is insulin. To lower insulin, the first step is to swap carbohydrates for protein and fat. Carbohydrates cause the highest insulin spike, followed by protein (moderate), while fat barely affects insulin levels.
It’s recommended to remove foods like oats and oatmeal, all cereals (even whole grain), bread, grains, fruit and fruit juices, quinoa, white and brown rice, potatoes and sweet potatoes, and all legumes. These foods can cause a significant glucose and insulin response. Fruit and fruit juices contain fructose and sometimes high fructose corn syrup, which can lead to fatty liver and visceral fat.
You should replace these with fat-burning, insulin-friendly foods such as cauliflower rice, squash rice, cabbage rice, whole eggs (with the yolk), red meat (beef and lamb), wild-caught salmon, organic poultry (chicken and turkey), and goat and sheep dairy (which contain more medium-chain triglycerides than cow dairy). Raw organic grass-fed cow dairy might be okay in moderation. Greens like arugula, broccoli, Brussels sprouts, and cauliflower are also beneficial.
Ideally, aim to drop your total carbohydrates under 50 grams per day to facilitate a metabolic switch to fat burning.
Stop Snacking: Snacking between meals raises glucose and insulin levels, even if it’s a healthy snack, disrupting your metabolism and preventing visceral fat burning. The average American eats 17 to 23 times per day due to grazing. You should aim for three meals a day initially and then work towards intermittent fasting.
Sprints: Sprinting is considered the best exercise to blast visceral fat. High-intensity interval training like sprinting activates hormones such as human growth hormone, making your metabolism more efficient at using stored fat for energy. The protocol involves sprinting at an all-out effort for 20 seconds, followed by 90 seconds of rest, repeated for three total rounds, three times per week. This should only take about 5 to 7 minutes.
No or Limit Alcohol: Alcohol is described as a poison and a toxin to the body that slows fat burning because the liver prioritizes metabolizing alcohol. Alcohol also stimulates appetite, decreases testosterone levels (which can last up to 24 hours), and can increase estrogen levels (especially beer), potentially contributing to an “estrogen belly”. It is recommended to avoid alcohol entirely or limit its consumption significantly.
Walking: Getting at least 7,000 steps a day (ideally 10,000) is crucial. Walking after eating a meal is particularly beneficial because it blunts the spike in blood sugar and reduces the amount of insulin produced, allowing you to get into a fat-burning state faster. Studies show that a 30-minute brisk walk after meals improves the glycemic response. Interspersing walking throughout the day in exercise snacks (three or four 2,500-3,000 step sessions) can be more effective than one longer walk. Aiming for around 9,000 steps per day is a good target. Even a rigorous 15-20 minute walk after a high-carb meal can significantly reduce glucose levels.
Intermittent Fasting: This has numerous benefits, including protecting against neurodegenerative diseases through autophagy, lowering insulin levels, increasing human growth hormone, reducing insulin resistance and blood sugar levels, reducing the risk of heart disease, boosting metabolism, extending lifespan, reducing inflammation, removing waste from cells, and helping with hormones like leptin and testosterone. The recommended schedule for visceral fat reduction is an 18/6 schedule, where you fast for 18 hours (consuming only water, electrolytes, supplements, coffee, or tea) and have a 6-hour eating window (e.g., 12:00 p.m. to 6:00 p.m.) with 2 to 3 meals.
90 Minutes of Deep Sleep: Deep sleep is when you burn fat and visceral fat, and most fat-burning hormones are activated. Aiming for 90 minutes of deep sleep each night is recommended. Scientifically proven tips to improve deep sleep include drinking banana tea, keeping the bedroom cold (around 65°F), ensuring the bedroom is dark (using blackout curtains or a sleep mask), using mouth tape to encourage nasal breathing, and taking 400-600 mg of magnesium.
The source also addresses the role of stress and protein intake in visceral fat reduction:
Stress: While insulin is the primary hormone for visceral fat storage, cortisol (the stress hormone) works with insulin. Chronic high levels of cortisol can lead to a “cortisol belly” and fat storage. Managing stress through optimizing sleep, addressing mental, emotional, physical, and chemical stressors is important. Activities that produce oxytocin (like hugging, watching something funny, hobbies, and practicing gratitude – “vitamin G”) can help combat high cortisol levels.
Protein Intake: The focus should be on protein intake when reducing carbohydrates. Prioritizing protein intake and eating it first during meals is recommended because protein is more metabolically costly to digest and assimilate compared to carbs and fat (20-30% of protein calories are used in digestion). Protein also helps you feel fuller for longer and can help with cravings. A general recommendation is to aim for 0.7 to 1 gram of protein per pound of your target or ideal body weight.
Regarding measuring visceral fat, the source provides the following information:
An indirect way to measure visceral fat is through a fasting insulin blood test. A result over 10 may indicate insulin resistance and visceral fat storage.
The most accurate way to test is with an MRI scan. CT scans can also visualize visceral fat but involve radiation. DEXA scans quantify visceral fat but don’t allow for visualization.
Visualizing visceral fat on an MRI scan can have a significant emotional impact, which can motivate individuals to make lifestyle changes. On an MRI, fat appears white, while muscle appears dark.
While software exists to quantify visceral fat numerically, visualizing the amount of visceral fat may be more impactful for individuals.
It’s important to understand that doctors do not routinely read visceral fat on MRI or CT scans. Dr. Anna C. Rosa is mentioned as one of the first radiologists to routinely do so.
If you’ve had a CT scan of your abdomen, you can review the images to see the amount of visceral fat.
Repeat testing with MRI can be done every 3 to 6 months to monitor progress. The cost and time involved with MRI scans can be limitations.
Insulin’s Role in Fat Storage and Reduction Strategies
Based on the sources and our conversation history, let’s discuss insulin hormone levels.
Insulin is the primary hormone in your body that signals fat storage, especially visceral fat. When insulin levels are elevated, a significant amount of fat is stored around your belly. This is a problem because this visceral fat puts pressure on vital organs and can contribute to chronic diseases like fatty liver disease, obesity, cancer, and heart disease.
The source highlights that carbohydrates cause the most significant spike in blood insulin when you eat them. Protein results in a moderate insulin response, while fat barely affects insulin levels. This is described as basic human physiology verified by medical textbooks.
When insulin levels are high due to carbohydrate consumption, your fat-burning hormones are suppressed and cannot function effectively. Insulin and fat burning essentially cannot coexist.
Therefore, the first step to burning visceral fat, according to Ben Azadi, is to lower insulin levels. This is primarily achieved by swapping carbohydrates for protein and fat in your diet. The source recommends avoiding foods that cause high insulin spikes, such as:
Oats and oatmeal
All cereals, including whole grain
Bread and grains
Fruit and fruit juices (due to fructose and potential high fructose corn syrup)
Quinoa, white and brown rice
Potatoes and sweet potatoes
All legumes (beans, peanuts, lentils, and chickpeas)
Instead, the source suggests replacing these with insulin-friendly, fat-burning foods like:
Cauliflower rice, squash rice, and cabbage rice
Whole eggs (with the yolk)
Red meat (beef and lamb)
Wild-caught salmon
Organic poultry (chicken and turkey)
Goat and sheep dairy (which have more medium-chain triglycerides than cow dairy)
Raw organic grass-fed cow dairy (potentially in moderation)
Greens like arugula, broccoli, Brussels sprouts, and cauliflower
The goal is to drop total carbohydrate intake to under 50 grams per day to lower insulin sufficiently and trigger a metabolic switch to fat burning.
Beyond dietary changes, intermittent fasting is also presented as a method to lower insulin levels. During the fasting period, insulin levels naturally decrease, which is beneficial for burning visceral fat and has other health benefits like increased human growth hormone and reduced insulin resistance. The recommended schedule is an 18/6 fasting window.
Furthermore, walking after meals helps to blunt the spike in blood sugar, which in turn reduces the amount of insulin required to clear glucose from the bloodstream. This allows you to get into a fat-burning state more quickly.
The source also indirectly links stress and cortisol to insulin’s role in visceral fat storage. While insulin is the primary hormone, cortisol (the stress hormone) works with insulin to promote visceral fat accumulation. Managing stress can therefore have a positive impact on insulin regulation.
Finally, an indirect way to measure visceral fat is through a fasting insulin blood test. A fasting insulin level over 10 may indicate insulin resistance, which is often associated with higher levels of visceral fat.
Carbohydrates and Visceral Fat Reduction: A Protocol
Based on the sources and our conversation history, let’s discuss carbohydrate intake in relation to visceral fat reduction.
The source “01.pdf” emphasizes that carbohydrate intake plays a significant role in the accumulation of visceral fat. According to Ben Azadi, carbohydrates cause the highest blood insulin response compared to protein and fat. Elevated insulin levels are the primary driver of visceral fat storage around the belly.
Therefore, the first and most crucial step in the provided protocol for reducing visceral fat is to significantly lower carbohydrate intake. The rationale behind this is that by reducing carbohydrates, you can lower insulin levels, which in turn signals your body to stop storing visceral fat and instead start burning it. The source explicitly states that when insulin is high from eating carbohydrates, your fat-burning hormones are suppressed and cannot effectively do their job.
To lower insulin, the source recommends swapping carbohydrates for protein and fat in your diet. It provides a detailed list of foods that people often think are healthy but can actually contribute to visceral fat due to their high carbohydrate and sugar content:
Oats and oatmeal
All cereals, even whole grain varieties
Bread and grains
Fruit and fruit juices because they contain fructose and sometimes high fructose corn syrup, leading to a significant glucose and insulin spike and potentially causing fatty liver and visceral fat
Quinoa, white and brown rice
Potatoes and sweet potatoes
All legumes, including beans, peanuts, lentils, and chickpeas
Instead of these foods, the source suggests replacing them with fat-burning and insulin-friendly options:
Cauliflower rice, squash rice, and cabbage rice as alternatives to white or brown rice
Whole eggs (with the yolk)
Red meat like beef and lamb
Wild-caught salmon
Organic poultry like chicken and turkey
Goat and sheep dairy (which are noted as being potentially better than cow dairy due to a higher content of medium-chain triglycerides)
Raw organic grass-fed cow dairy (suggested as possibly okay in moderation)
Greens like arugula, broccoli, Brussels sprouts, and cauliflower
The source provides a specific target for carbohydrate intake, recommending that you ideally drop your total carbohydrate consumption to under 50 grams per day. This level is suggested to be low enough to significantly lower insulin and facilitate a metabolic switch from burning glucose to burning fat, including visceral fat.
Our previous discussion on insulin hormone levels also highlighted the direct link between carbohydrate intake and insulin spikes [the previous turn]. We noted that carbohydrates have the most substantial impact on raising insulin levels compared to other macronutrients.
Furthermore, the source connects carbohydrate intake to other recommendations for visceral fat reduction. For example, walking after meals is particularly emphasized for its ability to blunt the post-meal glucose spike that occurs even with lower carbohydrate intake. This reduction in glucose also means less insulin needs to be released. Similarly, intermittent fasting helps lower overall insulin levels, which is partly achieved by restricting the time window during which carbohydrates (and other foods) are consumed.
In summary, the source posits that high carbohydrate intake is a primary driver of elevated insulin levels and subsequent visceral fat accumulation. To effectively reduce visceral fat, a significant reduction in carbohydrate intake to below 50 grams per day is recommended, along with the substitution of high-carbohydrate foods with protein and fat sources and insulin-friendly vegetables. Managing carbohydrate intake is presented as the foundational step upon which the other recommendations for visceral fat reduction are built.
Intermittent Fasting for Visceral Fat Reduction
Based on the sources and our conversation history, let’s discuss intermittent fasting as a strategy for visceral fat reduction.
The source “01.pdf” presents intermittent fasting as the sixth step in its seven-step protocol for burning belly fat. It is described as having many benefits.
How Intermittent Fasting Helps Burn Visceral Fat:
Lowers Insulin Levels: One of the primary ways intermittent fasting aids in visceral fat loss is by lowering insulin levels. As we discussed previously, elevated insulin is the main hormone that promotes the storage of visceral fat [1, our conversation history]. By abstaining from food for a significant period, insulin levels naturally decrease, which signals the body to start burning stored fat, including visceral fat.
Increases Human Growth Hormone (HGH): Fasting promotes a rise in human growth hormone. HGH is a key hormone that helps the body burn fat. The source mentions that studies suggest a significant increase in HGH hour after hour during a fast.
Promotes Autophagy: Intermittent fasting helps the body go through cellular cleaning processes called autophagy. Autophagy involves clearing out senescent (aged or damaged) cells.
Reduces Insulin Resistance and Lowers Blood Sugar: Fasting can help reduce insulin resistance and lower blood sugar levels. This is significant because insulin resistance is often linked to increased visceral fat storage.
Boosts Metabolism: Contrary to the misconception that fasting slows metabolism, the source states that it actually boosts metabolism.
Positively Impacts Other Hormones: Fasting can also help with hormones like leptin (the satiety hormone) and testosterone.
Recommended Intermittent Fasting Schedule:
The specific intermittent fasting schedule recommended in the source for burning visceral fat is the 18/6 schedule. This means:
18 hours of fasting: During this time, no food is consumed. You can have water, electrolytes, supplements, coffee, and tea. Snacking is not allowed.
6-hour eating window: This is the period during which you consume your meals. The example given is from 12:00 p.m. to 6:00 p.m.. During this window, you would typically eat two to three meals.
The source emphasizes utilizing sleep as part of the fasted state by having an earlier dinner by 6:00 p.m..
Connection to Previous Discussions:
Insulin: Our previous discussions highlighted that lowering insulin is crucial for visceral fat reduction and that carbohydrates are the primary driver of insulin spikes [our conversation history]. Intermittent fasting is presented as another effective method, alongside dietary changes, to achieve and maintain lower insulin levels.
Carbohydrate Intake: While intermittent fasting focuses on when you eat, the source also recommends what you eat during your eating window, which aligns with our discussion on lowering carbohydrate intake to manage insulin [2, 10, our conversation history]. Combining a lower-carbohydrate diet during the eating window with intermittent fasting is implied as a powerful strategy.
In summary, the source “01.pdf” strongly advocates for intermittent fasting, specifically the 18/6 schedule, as a valuable tool for reducing visceral fat. Its benefits are attributed to its ability to lower insulin, increase HGH, promote autophagy, improve insulin sensitivity, boost metabolism, and positively influence other hormones. This recommendation aligns with the broader strategy of managing insulin levels discussed in the source and our previous conversations regarding the impact of carbohydrate intake on insulin.
Walking for Visceral Fat Reduction: Steps and Timing
Based on the sources and our conversation history, let’s discuss steps and walking in the context of visceral fat reduction.
Walking as Step Five in the Protocol:
The source “01.pdf” identifies getting at least 7,000 steps a day, with 10,000 steps being even better, as the fifth step in the protocol for burning visceral fat. It specifically highlights that walking after eating a meal is the most beneficial time to do this.
Benefits of Walking, Especially After Meals:
Blunting Blood Sugar Spikes: When you eat food, your blood sugar levels will rise, even with a lower carbohydrate intake. This prompts the pancreas to release insulin to clear the glucose from the bloodstream. The more metabolically unhealthy you are and the more visceral fat you have, the higher this blood sugar spike can be, requiring more insulin. Walking after a meal helps to blunt this spike in blood sugars, requiring less insulin to be produced, and allowing you to get into a fat-burning state faster.
Study Supporting Postprandial Walking: The source references a study titled “the effects of postprandial walking on the glucose response after meals with different characteristics” which demonstrated that a 30-minute brisk walk after meals improves the glycemic response, even after high-carbohydrate meals.
Expert Opinion from Mike Mutzel: The source includes an interview with fat loss expert Mike Mutzel, who emphasizes that walking is a mandatory aspect of a healthy lifestyle, regardless of diet or fasting programs. He cites research suggesting a threshold of around 9,000 steps per day for overall health benefits and around 12,000 steps for preventing various diseases. A significant meta-analysis involving 1.3 million people found that at least 8,600 steps per day can help avoid and reduce the risk of developing conditions like sleep apnea, depression, high blood pressure, and improve metabolic health, including reducing visceral fat.
“Exercise Snacks” – Breaking Up Walks:
Mike Mutzel suggests breaking up your daily walks into “exercise snacks” of three or four 2,500 to 3,000 step sessions interspersed throughout the day, rather than one long bout of exercise. He argues that this approach can be more effective than a single longer walk.
Research by Edward Coyle on Step Counts and Metabolic Health:
The source discusses research by Edward Coyle at UT Austin, who found that:
Individuals walking less than 8,000 steps per day had an exaggerated postmeal level of blood triglycerides after a standardized high-fat test meal, which is a strong indicator of poor metabolic health and fat utilization.
There was a 30% reduction in fat oxidation in the low step count group (around 2,600 steps) compared to the high step count group (around 8,500 steps).
Interestingly, a 60-minute Zone 2 exercise session did not significantly increase fat oxidation in the low step count group, suggesting that daily walking activity is crucial for maximizing the benefits of structured exercise.
Walking After “Cheat Meals”:
Mike Mutzel suggests that even if someone has a higher-carbohydrate meal (like a “cheat meal”), going for a rigorous walk for 15-20 minutes can literally cut their glucose levels almost in half. This further reinforces the benefit of postprandial movement in managing blood sugar and insulin.
Connection to Previous Discussions:
Insulin: As mentioned, walking, especially after meals, directly helps in managing blood glucose levels, thus reducing the insulin response. This aligns with our previous discussions about the importance of lowering insulin for visceral fat reduction [our conversation history].
Carbohydrate Intake: While lowering carbohydrate intake is the primary dietary recommendation, incorporating walking helps mitigate the glucose spike that can still occur even with a reduced carbohydrate load [4, 5, our conversation history]. The synergy between dietary changes and increased physical activity like walking is evident.
In summary, the source strongly advocates for regular walking, aiming for at least 7,000 to 10,000 steps per day, with a particular emphasis on walking after meals to help blunt blood sugar and insulin spikes. Breaking up the total step count into smaller “exercise snacks” throughout the day may be more effective than a single long walk. Research indicates that achieving a sufficient daily step count is crucial for healthy postmeal metabolic responses and fat oxidation. This recommendation complements the dietary and fasting strategies for visceral fat reduction by directly influencing glucose metabolism and insulin sensitivity.
The World’s Easiest Diet For Visceral Fat Reduction In 14 Days | Ben Azadi
The Original Text
visceral fat is the nasty belly fat around your stomach I’m going to share with you in this lesson the easiest diet to follow to blast melt visceral fat in less than 14 days how do I know this can be done well this is a photo of me when I was 2050 lb 34% body fat I had a ton of visceral fat and I applied what I’m about to teach you and here’s what happened to me I went from 250 lb as you can see on the screen here to 170 lb right here here 34% body fat to as low as 6% body fat I had a lot of visceral fat those are signs of visceral fat you can see the love handles here and you can see what happened as a result before and after so you’re about to get the same results that I did I know this works because this guy right here me when I was 24 years old I was struggling with a ton of fat obesity I had pre-diabetes and high blood pressure and I tried so many different approaches and it wasn’t until I followed this approach that I’m going to share with you these seven steps to burn this fat that’s what I achieved in a short amount of time and I’m going to lay it all out for you right now the first step to burning visceral fat is to lower a hormone called insulin when this hormone insulin is elevated a ton of visceral fat gets stored around your belly this is a problem because that visceral fat applies pressure to your heart your kidneys to your liver and your pancreas and it creates chronic disease fatty liver disease obesity cancer heart disease insulin is the hormone that tells your body to pack on the visceral fat it’s the only hormone in your body that stores fat that’s pretty interesting because there’s over 600 hormones in the body but only one signal fat storage in that hormone is primarily the hormone insulin now cortisol works with insulin to do that but it’s insulin that’s causing this visceral fat all right now let’s unpack out of the three macronutrients out there which one causes the most insulin Spike well the research is clear when you eat carbohydrates you can see it creates the highest blood insulin response protein is number two but it’s a moderate insulin response and fat barely touches the dial on insulin this is basic human physiology all the medical textbooks verify this so if we know that it’s carbohydrates that Spike insulin the most that means the first step here in your protocol is to swap carbohydrates for protein and fat when insulin is high from eating carbohydrates you’re your fat burning hormones they go and they hide they cannot coexist with insulin so just to give you an example what are the foods people eat that they think are healthy but actually are causing visceral fat I’m going to show you some crazy stats right here these are some stats from chronometer doccom keto camp where you could input your food and it gives you the amount of grams of carbs protein fat it gives you all the calculations all the nutrition I input that into the system and I’m going to give you an example of the common foods people eat they think are healthy he but it’s causing weight gain it’s causing visceral fat so this is an example of an assai Bowl One assai Bowl from Jamba Juice how many teaspoons of sugar in that 20 teaspoons of sugar which equates to 99 gam of sugar that’s a huge blood sugar and insulin response all right Lucky Charms I know most people don’t think Lucky Charms are healthy but hey let’s look at the stats here in two servings of lucky charm so two bowls we have 12 teaspoons of sugar 60 g of sugar then we have oatmeal okay a lot of people try to lose visceral fat and they’re eating oatmeal they think oatmeal helps them lose weight does oatmeal cause an insulin Spike how much sugar is an oatmeal in just two servings of oatmeal there is 52 gam of sugar not to mention all the glyphosate and contaminants that’s usually found in oatmeal that’s besides the fact here orange juice people drink orange juice thinking they’re getting their vitamin C two cups of orange juice 16 o is 52 g of sugar therefore what you’re going to want to do to start tapping into visceral fat by lowering insulin is to remove the following Foods we have oats and oatmeal you want to get rid of that cereal that goes for all cereal even whole grain cereal all bread grains fruit and fruit juices because fruit and fruit juices contain fructose and sometimes high fructose corn syrup huge glucose and Insulin Spike that causes fatty liver and visceral fat you want to avoid quinoa white and brown rice you want to avoid potatoes and sweet potatoes all legumes including beans peanuts lentil and chickpeas ideally you want to drop your total carbohydrates under 50 gam total per day to lower insulin enough to make a metabolic switch to Fat metabolism fat burning where your body starts burning that visceral fat this is the first step that I did to start burning my visc fat now the question is what do I eat Ben you’re taking all my favorite stuff away there’s some really good food you can eat here’s what you want to swap them with you want to replace those foods with the following fat burning insulin Friendly Foods we have cauliflower rice squash rice and cabbage rice that’s a good replacement for white rice or brown rice we have eggs the whole egg with the yolk it’s amazing for insulin resistance fat burning amazing for fatty liver disease we have red meat like beef and lamb wild CAU salmon is amazing with its anti-inflammatory properties it has EPA and DHA it lowers inflammation allows your fat burning hormones to do their job we have poultry organic poultry ideally chicken and turkey I put eggs on there twice I guess I did that subconsciously because I love eggs so much goat and sheep Dairy would be better than Cow Dairy if you do cowery raw organic grass-fed cowery should be okay but the reason I put goat and sheep Dairy on this list as opposed to Cow Dairy is because goat and sheep Dairy contain 30% medium chain triglycerides which actually helps you get into a fat burning State faster than Cow Dairy greens like arugula which is a great bidder for your liver to detoxify and burn fat broccoli brussels sprouts cauliflower this is a good list of fat burning foods now there’s a lot more and I put together a recipe called the keto camp recipe of the week and these are recipes you can get by scanning the screen right there I’ll get out of the way for you uh or going to keto Camp recipes.com I’ll drop a link down below but these recipes I’ve worked with the food journalist for six months to put together insulin friendly fat burning recipes protein focused healthy fats low carbs and it takes all the guest work out of it so you just follow the recipes you get one a week in your email inbox and it’s easy and quick to make and it tastes pretty good all right Second Step here in your protocol is to stop snacking in between your meals every time you snack you raise glucose and then insulin even if it’s a healthy snack and here’s a crazy stat my colleague Dr Don Clum did a patient population study and he found out that the average American eats 17 to 23 times per day how is that possible it’s the grazing the handful of almonds the sip of the kombucha the protein shake every time you eat if it’s a snack or a full-on meal it doesn’t matter it’s a meal to your body it’s going to disrupt your metabolism it’s going to prevent you from burning visceral fat the example I always give is like this example here let’s say you’re in your office at home and you’re in a flow State working very productive and every 2 to three hours somebody bangs on your door and disrupts your your workflow that’s what’s happening to your metabolism when you eat every 2 to three hours your spiking glucose and insulin and you’re disrupting your fat burning workflow so the first step here along the Second Step I should say along with the first step is to eliminate the snacks you’re going to start by just having three meals a day and you’re going to work your way up to intermittent fasting which will discuss how that helps you burn visceral fat in a second the third step to burning belly fat are Sprints sprinting is the best exercise you can do to blast melt visceral fat I’ll share with you the protocol and it’s pretty easy by the way it might seem too little but I got to tell you it works like a charm but let me explain how this works when you do high-intensity interval training a Sprint at an allout effort and then you rest and recover and repeat that a few times you activate hormones in your body that like human growth hormone and others that really allow your metabolism to get more efficient and use stored fat for energy it’s a very energy demanding activity Sprints and you’re going to allow your your body to burn through your sugar reserves called your glycogen stores and then make that metabolic switch to blasting stored fat visceral fat for energy so the protocol is very simple you do this three times per week you’re going to Sprint all out effort for 20 seconds either outside or on a treadmill you could also do it on a bicycle by the way if you have bad knees all out effort like a lion is chasing you for 20 seconds time yourself then you’re going to rest for 90 seconds total ideally you want to sit down maybe lie down for 90 seconds allow your body to go back into a parasympathetic State and then you do it again 20 second all out Sprint you can do that for three total rounds and you’re only going to do that three times per week maybe it’s Monday Wednesday and Friday they should only take about 5 to 7 minutes you might want to warm up beforehand but 5 to 7 minutes what a wonderful way and a fast easy way to burn belly fat so sprinting is the third step here the fourth way to burn visceral fat sorry to be the be bad news but this is no alcohol or limit alcohol but if you go no alcohol even better look before I get into these stats here alcohol is a poison to your body it’s a toxin to your brain even if it’s the cleanest alcohol in the world the most expensive alcohol every sip will kill brain cells inside of your body but it’s not just that as it relates to visceral fat your liver is a very important organ not just for detoxification but for fat loss and when you have alcohol your liver and your metabolism needs to metabolize and prioritize getting rid of that toxin the alcohol before anything else before fat burning before any other detoxification processes so you slow fat burning and another reason why is alcohol stimulates appetite and decreases testosterone levels for up to 24 hours so you’re probably going to eat more carbohydrates eat unhealthy you’re going to have lower levels of testosterone and it can increase estrogen levels especially beer by 300% this is why they call it an Infamous beer belly it’s really just an estrogen belly biochemically the higher your levels of estrogen are the more readily you absorb alcohol and the slower you break it down it becomes a vicious cycle so have a mocktail that’s not sweetened have sparkling water this is what I do sparkling water with a Sprinkle of lemon sometimes I’ll put some drops of stevia monk fruit but no alcohol if you’re serious about burning visceral fat okay the fifth step here in your protocol is walking getting at least 7,000 steps a day 10,000 steps are even better but doing it after eating a meal after eating your meals is the best time to do this because when you eat food you’re going to have blood sugar Spike even with the lowering of carbs that we mentioned in the protein and fat there’s still going to be a rise in glucose and the more metabolically unhealthy you are the more visceral fat you have the higher that blood sugar Spike the higher that blood sugar goes after eating the more insulin is required from your pancreas to be pumped out to clear that excess glucose out of the bloodstream and into your cells that’s not good the more insulin the more you store fat so by going for a walk you blunt this big spike in blood sugars and you allow less insulin to become produced meaning you get into a fat burning State faster walking is one of the best things you can do and this study proves it and there’s numerous studies that show this but this study titled the effects of postprandial walking on the glucose response after meals with different characteristics so what this study did they took participants in three different groups one group ate a low carbohydrate meal one group ate a mixed meal of carbs and fat and protein and the other group had a straight up high carb meal and all three groups when they walked for 30 minutes after a meal saw positive results here’s what the study said although higher glucose levels were observed with High carbohydrate meal are finding show that a 30 minute post prandial meaning after eating brisk walk session improves the glycemic response after meals huge so 30 minute walk after all your meals and if you can’t do it after all your meals do it after your biggest meal of the day I interviewed a world renown expert uh Mike mutel who’s a fat loss Fitness expert and a good friend of mine and he’s going to share with you right now why walking is one of the best ways to burn fat visc fat overall body fat and extend your lifespan so check out this clip it’s going to blow your mind from Mike mutzel if people wanted to shed stubborn Fat Mike how can walking help with this and what is the right method of walking to make this more efficient Ben great question I think people need to think about walking as a mandatory aspect of their lifestyle irrespective of whatever diet or fasting program they’re doing uh various Studies have been emerging over the past I want to say five or six years finding that the threshold for the number of steps that we should be walking every day is right around 9,000 so that’s what people should aim for uh other studies show about 12,000 for preventing different diseases and these are common conditions there was a huge metaanalysis involving 1.3 million people finding that if you walk at least 8600 steps per day you can avoid and reduce your risk of developing all sorts of conditions from sleep apnea to depression to uh high blood pressure pressure improving metabolic Health producing visceral fat um so that’s really important but getting back to your question specifically about losing belly fat um we should be breaking our walks up into what I I consider and researchers talk about this exercise snacks so having three or four 2500 step sessions interspersed throughout the day so you know people are always wondering like well will coffee break my fast will this or that break my fast walking actually helps you uh trigger the the autophagy mechanisms that are some of the health benefits linked with fasting uh we can get into the the sort of synergy between exercise and autophagy and the parallels with fasting later but but to get real granular with this 3 to 4 2500 or 3,000 step sessions and so what that might look like is before you have uh breakfast in the morning a lot of people fast in the morning a lot of your listeners do that um just go out and get 2500 3,000 steps you know and then around after lunchtime after your first major meal um get another 3,000 steps and then after dinner you get 3,000 and if you do these little exercise breaks it’s actually more effective than just going to the gym and doing say 45 minutes on a treadmill or a 45 minute walk so interspersing exercise and walking throughout the day uh is better than just doing one bout of exercise and I like to share the research from a gentleman known as his name is Edward Coyle at UT Austin and he’s published many randomized control trials where uh they randomize subjects to either a low step count group medium step count and High Step count and to enumerate those step counts we’re talking 2600 steps for a whole day so just relegating people to a lab where they’re only walking with their pedometer 2500 steps and then they randomize people to either walk 4,500 steps or 9,000 steps and then what they do after just this is I think two and over the course of two and four days depending upon which study they published they’ve done a few of these different trials then after those interventions uh they will give the sub subjects a standardized high fat test meal and they’ll look at markers of fat oxidation as well as postmeal hypertriglyceridemia so I know you talk a lot about lipids and and biomarkers high postmeal triglycerides are a strong independent risk factor of future heart disease as well as metabolic deterioration and it’s a proxy of poor fat utilization and handling and poor fat oxidation so you don’t want a strong High postmeal triglyceride level would suggest that you have some degree of poor metabolic health and so what the investigators found is when people do not walk at least 8,000 steps per day after the standardized test meal they have an exaggerated postmeal level of their blood triglycerides which as I mentioned very problematic arguably worse than LDL cholesterol which we can get into later and the differential in fat oxidation between the low step count group again most people are just walking about 2,000 3,000 steps per day you know they get up they walk they go to the car they drive to work they get in the office they sit all day then they drive home and watch TV and so most people are pretty sedentary and there was a 30% reduction When comparing the high step count group around 8,500 steps compared to the 2600 step count so if we think about just two days and this is some people might be traveling going to Yos or Yellowstone with the family they’re in an RV wi AO they’re eating you know chips and hot dogs and things like that sitting around or on a on an airplane you know so we do this uh all people do this all the time and we wonder why we can’t lose fat and this just this is one very simple way uh to just improve your body’s ability to burn fat because going further what the study did is they also in one arm of the study they had individuals do a 60 Minute Zone 2 exercise session which as we know zone two is actually I don’t think it’s the best for long-term fat loss but when you’re doing Zone to low intensity cardio you tend to the body relies more upon burning fat for fuel to uh give your muscles energy during that exercise session there wasn’t a statistically signific significant increase in fat oxidation in the low step count group meaning that if people don’t walk a lot but they go to the gym they’re not getting the most mileage from that gym session because they’re not just doing these daily uh activities of daily living that are supporting fat oxidation so yeah to be very concise three to four sessions uh walking sessions of you know 250000 to 3,000 steps interspersed throughout the day and honestly Ben this is great for mental focus I mean you can only focus on a one you know finite task for a short period of time uh and so this just really helps break up the day you feel better you digest your food better we can get into the ciran Rhythm health because I encourage people to walk outside even on a cloudy day the uh the intensity of the Sun the Lux uh is is well over a thousand which really helps Toc entrain your circuiting clock system and Foster that sleep pressure later in the day so there’s a bunch of different health benefits uh but yeah it really helps people lose a lot more belly fat I’m sold I I have I have been sold for quite some time you broke it down so well and the evident this this research is clear that it’s beneficial especially when you chunk it out so 9,000 steps per day seems to be the target uh I tend to get around 12 or 13,000 on average per day and it’s chunked it’s not in one long workout so I tend to do that naturally with my day-to-day it’s the benefit of having a dog by the way it’s I walk him at least twice a day so I get outside you mentioned going for a walk after dinner I’d love for you to share the benefits of going for a walk after eating uh maybe a higher carve meal of what it does to kind of blunt that post pral glucose yeah this is amazing and and the way that I sort of figured this out I mean obviously there’s research you to show this but back when continuous glucose monitors the Abbott freestyle came on the on the market back in 2017 um you know I had been doing keto eating a low carb diet since 2014 got into it and I was like you know kind of curious like if I were to go to a vegan restaurant uh here in Seattle I went to I just Google the most popular vegan restaurant um my family went in there and we just said hey we’ve never been here before give us your your the most popular items on the menu and it was you know pizza and some Breads and some different things and I’m testing my glucose in real time I calibrated the glucose monitor and so forth and I could see my glucose start to continuously in increase to 185 Mig per deciliter and so for folks listening that is in the pre-diabetic range now I know that might sound alarming people are like well you’re diabetic it’s like no I had been used to eating a low carb diet for a while and research shows this when you get habitually accustomed to eating a low carb diet and then you have a very high carb meal your body can have an OV exaggerated response to that meal and that’s exactly what happened and you know I was like oh my gosh we need to go for a walk to get this down and no kidding Ben I went for my usual one mile walk with the dogs uh came back and my glucose went from 185 to 85 milligrams per deser and I I made a video on this and I was just blown away you know we hear all the time about exercise is good for fat loss exercise helps with blood flow exercise you know helps reduce glucose and and and improve the valley the Peaks and troughs and glucose levels but in real time I was able to see this and I thought wow this is really powerful and it really speaks to when go to other parts of the world you know I know some of your audience lives outside of North America but most are relegated to North America that’s just kind of how YouTube works and you know when you go to Europe and other places people just walk you know they don’t have cars and and things like this they have public transportation but you know people are walking in this but yet they’re eating bread and baguettes and pasta you’re like well why don’t we see the Obesity uh in parts of Europe where they do have a relatively High carbohydrate diet and my uh hypothesis is that they’re just walking more they’re just more active and and moving around more so that I think is really important so if someone does have a cheat meal someone listening is going to go to a birthday or a wedding or have a barbecue and there might be Temptations with a hot dog or some chips or some ice cream or whatever if you just go for a rigorous walk for 15 20 minutes that’s all it takes you can literally cut your glucose in half by doing that and obviously there’s many health benefits too because you insulin you know if you are normally low carb and then you have a high GL glucose or high calorie meal um you’re going to have an OV exaggerated insulin response to that and and we know there’s downsides to insulin in terms of uh facilitating AOS sclerosis and the formation of plaque in your arteries uh inflammation immune suppression there’s a a long list and so by just helping your body do what insulin would normally do and put glucose into your muscles by moving your muscles you’re causing them to absorb uh that glucose and and we already know this in the postmeal window about 80% of glucose is deposited in skeletal muscle so if you just add some stimulus there by walking because people don’t think about muscle as an organ it’s an organ just like your thyroid just like your liver just like your pancreas but in order for this organ to work it needs stimulation and so we need to stimulate this organ through activity and that’s where exercise really comes in and people don’t think that walking is an exercise but it really is you know you’re moving those muscles and I will tell you there’s research out of Copenhagen uh researchers in Denmark outside of Copenhagen have done uh studies finding that in diabetics the leg muscles become insulin resistant before the musculature in the upper body and I know people go to the gym they lift you know chest and biceps and and I do that stuff too I I like lifting weights but you you need a lot of stimulation in your legs because for some reason they become sort of disease likee before the musculature in the upper body and I would argue that part of that is because we have through natural collection and and just how humans are either hunting historically ancestrally hunting or gathering we’re moving we’re never meant to sit in our cars for three hours a day and and Rush our traffic or sit in desks we are always we should be moving and this is one of the things if you look at the Blue Zone research we’re hearing so much push about well you got to go on a plant-based diet because see these blue zones eat plant more plants than meat you know depending upon the Blue Zone so therefore the plant-based diet is the the key here it’s the sinanan of longevity well not so fast these Blue zone areas are are also characterized by a lot of recreational activity in Sardinia in parts of Costa Rica in Japan these people move they don’t sit in their cars they’re they’re you know moving throughout the day having these so-called exercise snacks so uh again if you have a cheat meal go for a brisk walk it will literally cut your glucose levels almost in half well there you have it I hope Mike Mel and I have inspired you to get at least 7,000 steps a day but get those steps after eating your meal for the best visc Al fat burning response your next tip number six is to practice intermittent fasting there are so many benefits to in fasting here are some of the benefits I love and there’s a typo right there just ignore that typo so here’s one of the benefits you protect against neurodegenerative diseases that’s because your body goes through the cellular cleaning process called autophagy where it clears these senescent cells insulin levels drop and human growth hormone increases that is key for burning visceral fat we already established we need a lower insulin obviously fasting does that but human growth hormone is one of the key hormones that helps you burn body fat and as you practice fasting you get a rise in human growth hormone studies suggest huge increase in human growth hormone hour after hour during a fast this is your body’s way of pumping you full of energy because it thinks you’re going through a famine it doesn’t understand this it’s just hard wired this way one of the other benefits you reduce insulin resistance and lower blood sugar levels obviously you reduce risk of heart disease you reduce blood pressure and overall lipids boost metabolism Because by the way it does not slow down your metabolism when you fast it does the complete opposite studies suggest it extends lifespan reduces inflammation removes waste from cells and also helps with hormones like leptin which is your satiety hormone and testosterone so the schedule you’re going to follow for intermittent fasting is an 186 schedule this is a great schedule for burning visceral fat something I do on a daily basis this means for 18 hours you’re in the fasted State no food what are you having in the fasted State just water electrolytes supplements coffee tea that’s it no snacking no food for 18 hours so that would mean you have a 6-hour eating window to get your food and your protein so for example from 12: to 6:00 p.m. you have your eating window you’re going to eat 2 to three meals between 12: and 600 p.m. this little window right here from 6:00 p.m. to 12:00 p.m. the next day day you can see from 6:00 p.m. to 12:00 p.m. the next day you’re in your fasted state so you’re using sleep as that fasted State you’re having an earlier dinner by 600 p.m. that is an 186 schedule that I want you to follow to tap into visceral fat the seventh step here in your protocol is to get 90 minutes of deep sleep there are four main stages of sleep each night you have well when you’re awake and then you have three main cycles of sleep light sleep deep sleep REM sleep all are important REM sleep is great for it’s called rapid eye movement it’s great for U consolidating short-term memory for long-term memory great for focus and mental Clarity but the deep sleep right here this is where you burn fat this is where you burn visceral fat this is where most of your fat burning hormones are activated and you’re really tapping into stored fat for energy and you want to aim to get 90 minutes each night of this deep sleep you could track that with like an aura ring I have an aura ring here I’ll put a link for it in the notes down below Apple watches fitbits bands there’s many devices I’ll drop links for many of them all of them down below in the notes for you to check out personally I like my my aura ring but if you could achieve 90 minutes of deep sleep this Delta sleep each night you’re going to accelerate your results with burning visceral fat so here are some scientifically proven tips to get more deep sleep starting tonight number one drink banana tea I call it Nature’s NyQuil now I got this from my colleague Dr Michael Bruce banana tea you grab a whole banana cut the ends off but you leave the peel on because the peel of the banana has more micronutrients like potassium and magnesium that help you calm down than the actual itself and you boil it for about 5 minutes and then pour that into a cup and just drink the tea great for somebody who has a racing mind at night drink some banana tea cold bedroom studies suggest that your room needs to be about 65° fahr to get that deep fat burning Delta Sleep set that thermostat to around 65 degrees Fahrenheit dark bedroom you don’t want anything with light at night don’t have the television on put your alarm clock far away put your phone out of the room or turn shut it off and if you can have blackout curtains that’s best but you could also just wear a sleep mask I use the one from bonch charge which I’ll drop a link for down below but you want to make sure no light going through your eyes or on your skin to get deep sleep at night mouth taping is a game Cher for deep sleep when you breathe through your mouth at night you are not going to get enough deep sleep you’re going to deplete nitric oxide and you’re going to feel groggy in the morning and it’s going to be hard to burn fat you want to breathe through your nose so I simply wear an adhesive a piece of tape from somnifix and I’ll drop a link for them down below every night I just put this on before bed and it trains my body to Brea breathe through my nose where you get more into a parasympathetic state so you get more deep sleep you increase nitric oxide which is very important for cell communication and something called Vaso dilation some mouth tape at night I’ll drop a link for them down below and then lastly take some magnesium 400 to 600 Mig of magnesium I’ll drop a link for my favorite one down below now let’s get into some of your questions here that you said submitted and by the way if you’re watching on YouTube keep submitting those questions cuz we use them for videos I want to address all your questions what role does stress play with visceral fat that’s the first question as I mentioned earlier insulin is the only hormone I should say the primary hormone that stores visceral fat but cortisol works with insulin cortisol is the stress hormone so it plays a huge role you want to make sure you’re mastering your stress and by optimizing your sleep that’s already going to help you master your stress but stress comes from three different areas mental emotional physical and chemical so address all three if you’re stressed out watching the news watching television seeing what’s happening in the world uh having toxic relationships I know it sounds like how could this cause visceral fat well it’s called a cortisol belly for a reason when you have high levels of cortisol chronically high levels of cortisol you’re going to create a cortisol belly and you’re going to store fat so yes master stress one of the best ways to combat high levels of cortisol is with the hormone oxytocin you you see oxytocin and cortisol have an inverted relationship when you produce oxytocin cortisol drops how do you produce oxytocin I’m glad you asked hugging your dog or another human being for 10 seconds or more will produce oxytocin watching something funny will produce oxytocin doing something you love like a hobby for me it’s basketball will produce oxytocin vitamin G is the best way to produce oxytocin you want to talk about the best supplements in the world for visceral fat and chronic stress and oxytocin production vitamin G is where it’s at now I don’t have an affiliate link or a coupon code for vitamin G because vitamin G is the practice of gratitude you can see here in my shirt vitamin G what you appreciate appreciates and I’m being serious studies show numerous studies that the more gratitude you have in your heart and I’ve named it that gratitude is strength training for your soul I love that line thought about it when I was walking my dog the other day put it in the comment section if you’re watching on YouTube gratitude is strength training for your soul you get an immediate benefit there’s no upper limit on vitamin G it’s free and vitamin G gratitude will activate cortisol and Gaba and dopamine and it combats cortisol helps you burn fat next question is how much protein should I have to burn visceral fat we established that you want to have less than 50 gram of carbs total per day the focus should actually be protein and I brought on JJ Virgin on the metabolic Freedom podcast and she’s going to give you a Master Class A short little tip here on how protein helps you burn visceral fat so check out this clip with JJ Virgin the first one I love so much because it’s going to solve a couple problems because if you’re trying to lose fat at some point you’re going to have to go into a caloric deficit and you’re going to have to achieve it one way or the other and if you’re hungry and having cravings that’s out the window so the easiest way to be able to get into that at some point which we will talk about but this is the first big rock is to eat protein first is to prioritize protein but I I say eat protein first because I have been at too many dinners and heard too many times from women that they get too full to eat their protein and I’m like well I just sat at dinner with you and I watched you have a salad with cranberry raspberry vinegarette glazed nuts you literally had it a sunde then you had some bread then you had some appetizer like calamari and then you say that you and I’m talking fried calamari so you’re mainly getting dough and fried right and then finally your meal comes and it’s like some kind of starch and veggie and a little protein and you eat the starch then you finally get over the protein of course you’re full so the easy way to solve this is to eat protein first now why do I want you to do this so when you look at our three macronutrients you know along with water that we must have to survive which it’s interesting we do not have to have carbohydrates to survive as you know you know protein and fat and water we must have we can live without carbs which it and I know this must make you crazy too Ben it’s like why did we design an entire diet based on the one thing that we can live without how is it working for us not good you know so you know let’s focus on the protein and the reason I love that is a couple things number one when you’re eating Whole Foods proteins like wild salmon grass-fed beef you’re going to get healthy fats too so you get everything you need and then drink a bunch of water with it the reason I want people to focus on protein first is protein compared to carbs and fat is so much more metabolically costly to digest and assimilate where fat really takes nothing to get on your body and be burned as fat or stored as fat and we have a great storage Depot pretty much unlimited for fat then carbs maybe 5 to 10% is the processing to either get them stored in your muscles as glycogen which is what we hope we have like liver and muscle or turned into fat which is what we hope we don’t do or just burned and then we’ve got protein 20 to 30% of the of the energy that we take in when we take in protein has to be used in the digestion and assimilation of protein how cool is that so 100 calories of protein is only really 70 calories probably or 75 contrast that with 100 calories of fat is 100 calories so that’s the first part of it the second piece of it and you would you would think and this has actually been shown is that if all you did initially this would help you initially it’s not going to be a long-term fix but initially if all you did was take some of the calories away from fat carbs and move them over to protein you would eat less overall because you wouldn’t be as hungry but You’ take in less calories overall too it’s not a huge effect but it does make a difference and everything counts but the second reason I love protein is because it’s going to make you feel Fuller longer everyone’s talking about glp 1es and I’m like all right we’ll just eat protein it’s one of the you know nature Nature’s little glp1 Agonist protein so protein not only helps us with Hunger but it also helps us with cravings and as you know those are two very different things and so you know now you’ve got the building blocks we turn over 300 plus uh grams of amino acids a day in our bodies and we need the protein we need the essential amino acids from the protein to make the other amino acids and then to make neurotransmitters that will help shut down our Cravings so we we’re not hungry we don’t have the Cravings we’ve got a better ther effect so that’s where I really like people to start because it just makes the rest of this easy and it’s something you can do whatever diet you’re following so I always do that like let’s like not get into some the diet religion and the diet Wars you could do this plant-based you can do this carnivore you can do it whichever way you do it but start with making protein 7 to one gram per pound of Target body weight you can even push it a little higher if you’re working on recomping and put that as your first thing that you eat before you eat anything else so that’s I was going to ask you how much do you recommend so 7 to one gram per ideal body weight can you share how somebody would calculate that based off of somebody who’s overweight right now they’re trying to lose weight yeah and I mean here’s the thing and this is what I used to do but it just got so complicated in the perfect world we would go get a dexa scan we’d find out our Target body weight that we’d really want to be but based on more of our skeletal muscle than dose it per skeletal muscle all right you know what the minute we start to make things hard then people have a reason why not to so you know that weight you feel good at right now I’m gonna I’m going to say that we always want to look past weight to what that weight’s made up of as the most important thing however let’s just not get into the weeds of should it be 140 pounds or 160 pounds pick a weight and then just look at that weight and let’s say it’s you know 150 pounds so you’re going to go 7times 150 would be how much is your lowest amount and then you could go up to 150 grams and really you can go higher I mean this you know there so much research has come out lately about protein intake because it used to be that don’t eat more than I I remember I got a DM you’ll love this I got a DM my manicur has told me that I should not eat more than 27 grams of protein at a meal because I’m like because what what will happen where will it go you know because I’m like it’s got to go somewhere it’s not going poof you know we can take protein and we could use it as fuel our body doesn’t want to so you know it’s like it’s going to try to use it more and break it into amino acids and use it to rebuild but if it had to use it it could turn it into sugar and you could use it for fuel or you could turn it then and put it into glycogen in the muscles or you could turn it into fat and store it so you can do any of those things it’s not GNA like turn into some evil rampaging monster in your body do not worry you know it’s like everyone’s worried about overeating protein I’m worried about you overeating sugar and damaged fats and Ultra processed food I don’t think we’ve ever seen anyone you know who’s in the hospital because they were you know they just had a really really uh Pig Out diet on wild salmine and they got no that doesn’t happen no one ever I mean even you know look at carnivore are you getting people sick because they’re eating grassed meat no we get sick because we eat Ultra processed foods you know that’s why we’re sick there you have it so I always say get one gram of protein per pound of your ideal body weight so if your ideal body weight your goal weight is 120 lbs you want to get about 120 grams of protein J to just establish how important that is for lean muscle mass visceral fat satiety and all the other benefits fourth question how do you measure visceral fat there’s an indirect way to measure visceral fat that’s with the fasting insulin it’s a blood test and if you see that over 10 you have insulin resistance you’re storing visceral fat cheap test to get got to ask for it from your doctor the most accurate way to test is with a skin and I brought on a visceral fat expert this guy has reviewed thousands of visceral fat scans he is the world leader on visceral fat and one of my dear friends Dr Shan Omar and he’s going to share with you how to actually measure visceral fat and if you’re listening on the podcast we’ll explain it in a way for you to understand what we’re sharing so check this out what are the best ways of measuring uh viseral fat you can measure it uh quite accurate through a dexa scan uh but let’s just be honest those of you um that are aware of somebody that’s kind of a dexus SC for the purposes of looking at visceral fat let me ask you a question uh what kind of effect or influence did that have so uh what happens when you get a dexus scan it gives you a number and when you get an MRI scan or you get a CT scan of your abdomen uh which you you can get a number because there’s software that can be uh that can quantify your visceral fat but uh I was just sharing with a radiologist of yesterday that runs A rad Radiology system that um it’s it’s not even important for me or a doctor to look at that MRI scan you know who’s the most important person look that scan the person who did it the the person yeah who went and got it so so you can see the visceral fat inside you because uh once you understand that visceral fat the enemy for what it is and how problematic it is then you don’t want to interpret your the the problem you have through a numeric reduction to a numeric figure and that’s what you you get when you do a dexus scan but when you stare at that the abundance of white that white Enemy Inside of You by an MRI scan or if it’s a CT scan your your adomen and uh the difference between CT scan and your MRI scan is uh they’re both about as good of resolution a higher resolution MRI but it’s it suffice suff it’s a sufficient uh modality to look at visceral fat by CT scan the downside to it is the radiation that’s required when you get a CT scan and an MRI scan doesn’t use any radiation at all it uses safe magnetic fields uh so uh from a standpoint of safety the MRI is higher resolution uh no radiation required uh but um CT is an important part of the discussion because uh women who are listening many of you have had CT uh down scans and you need to go back and take ownership of that and do two things one uh look at the report the report generated that will have been interpreted will be bereft and devoid of any mention of visceral fat no doctor ever reads visceral fat that’s starting to change Dr Anna C Rosa R OA is the first radiologist that I’m aware of who is now routinely reading visceral fat fat around the heart fat within the muscles and deep subcutaneous fat in the world wow nobody else is reading if you’re a radiologist I think you need to to grasp that you just like me as an MD it was kept from you in medical school and kept from you in Radiology residency it’s the largest part of the adomen in most people and is completely ignored and it’s because in my opinion it’s the influence of the curriculums in medical school from Big Pharma uh that’s keeping it out of our curriculum to teach doctors uh but you need to visualize the visceral fat insidey the M MRI is the best way uh to do that and uh it’s uh when when people visualize it I get lots of colorful language the f bomb is dropped all the time my my my office when that happens uh people get very upset uh I’ve had uh clients get so upset that one I remember thinking I may have to call the police because they were dropping the f bomb so much they couldn’t sit and they run around you know standing up walking around saying this is the last eff in time I changed my life you know and and there I had other clients out in the waiting room and I was like this is super embarrassing they were all sorts of colorful uh language well some sometimes that emotional impact is needed to make the change that’s your that’s your point you know you see that with the image seven years later that guy is still nice and lean and healthy now it changed his life completely around I’ve had other clients uh one one client that I’ve told the story literally passed out when he visualized how much viseral fat that he had inside and so for that reason now I require all my clients to sit down I don’t let them stand because this guy was standing and he fell he went unconscious right in front of me U because he was so upset when I showed how much visceral fat he had now keep in mind if you’re you know clients if you’re watch or patients are watching today that you have to understand what visceral fat is and so um can we so can can we um do you have images on your phone that you I do yeah so what we’re going to do for those watching on YouTube if you’re listening on the audio podcast uh we’ll explain it in a way where you can understand what we’re showing but it’s better for you to go to youtube.com/ Kamp maybe after you finish listening so we could see exactly for those watching the visual impact of somebody who has a lot of visceral fat and then somebody who has a healthy amount a small amount of visceral fat so we’ll show that to you in a second yeah so yeah it’s really important I think for people to understand a little bit about visceral fat they need to know what a good amount is and so when people come I spend probably about half hour you know going through good examples like of a people with a low amount of visceral fat and people that have a high amount of Vis start with good or bad what are we starting with uh so th this is both good and bad um yeah so we’ll put that on the screen as well but show and I can we’ll send these images so the top image is somebody has um just a a moderate amount of visceral fat so pretty good but the bottom image you can see this person is filled with a lot of white so on an MRI scan fat shows up as white so this is Gabe a friend of mine from the Army National Guard I use his example a lot and uh for a a relatively modest amount of visceral fat and then this is uh assf at the bottom image who has huge amount of viseral fat and you want to be mostly dark you know Gabe is mostly dark he’s got big muscles oev is mostly white and when you have a lot of white you have a small amount of dark because the white uh unfortunately uh causes atrophy sarcopenia so we see a a deposition a reduction and visceral fat and this is this is a great example that almost all dark this person has the the smallest amount of visceral fat I’ve seen in a female W and uh she’s on social media um this is Karen Lauser she gives me permission to show her image and uh God bless this woman I mean I show show her a picture you she’s got 600,000 followers she is a very healthy looking woman she she actually is very attractive she’s a model and the reason she’s so attractive is because um she’s never had visceral fat she it’s the influence of visceral fat not the presence of visceral fat that causes people to have disease so you can accumulate a lot of visceral fat in a very short period of time and look great or um you can have a small amount of visceral fat over a long period of time and that influence that trickle trickle trickle of all the inflammatory molecules that come from it deteriorate your level of health and your appearance so if you see somebody who’s older Carolyn is 59 wow she looks amazing yeah yeah and so I’ve been on her on her on her Instagram live with her and God bless her she is um very dedicated to her followers she takes her role as a social media influenc are very serious her and her husband uh frequently do uh shows together and so she is routinely promoting uh health and because she enjoys uh uh talking about the topic and she herself has you know a very healthy appearing body so um it’s it’s really necessary to understand um visual fat where it is uh within the abdomen this is the little tiny divot U right there at the top is belly button oh that’s her belly little divot at the top there got it is is it giving you a total percentage of visceral fat like a total body fat or is it giving you certain areas and their percentages or maybe not at all you’re just looking at the photo and stad yeah we’re for us we just have people look at um how much visceral fat they have there is software out there and it’s free by the way if you are a radiologist and you want to start um scanning and reading uh visceral fat and you want to both quantify it uh with a numeric value um uh as well as qualitatively share it uh with with patients they get through it uh there is free software that will actually quantify now when when we were studying our startup for the National Science Foundation uh we we were spending money on software development to do our own proprietary system to quantify we actually abandoned it we had the ability to to measure it and we stopped measuring it because it it didn’t have any uh demonstrable impact on our CLI it was you because you give them a number you really want to show them U that that bad amount of fat so uh here’s another example of somebody has a huge amount of visceral fat show it to the screen so camera knows what put on so uh in the top uh example here is somebody that has a very large amount of visceral fat oh we lost it oh uh very large amount I’m glad you picked that up um of visceral fat uh in that top image and these are their legs corresponding leg images you see all the white streaks and those um leg images are from fatty infiltration of a a fat within the skeleton muscle or it’s fatty replacement of muscle tissue or it’s also called adverse muscle composition or myosteatosis is the technical term for it so the more visceral fat you have the more of this in inflammatory infiltrating fat you have going on within your skeletal muscle and you know you can understand why your muscles would would stop be performing as well and nobody’s talking about it’s completely ignored by doctors when you when CTS are done MRIs are done they don’t talk about either visceral fat or those fatty infiltrates and then here’s another individual has mostly muscle inside very very small amount of visceral fat and their legs are very lean very dark they look like Fong there’s no marbling or fatty infiltration going on so very different between those two comparisons yeah I call them bricks and clouds difference uh that that uh this image up up up on the top Corner looks like human wagu wagu human skeletal muscle moralization of the skeletal muscle so um I think it’s really important to to uh to have good accurate uh imagery of of these targets and dexa scans don’t allow you to visualize it they quantify it uh CT scans allow you to visualize visualize it you can quantify it through CT scan but there’s radiation but one of the reasons why I talk about CTS again as I mentioned earlier is because so many people have had them you need to go back and and get that report but take a look at that image yourself you’re entitled to it that’s your record go and look at the amount of visceral fat uh that you have within your CT skan of your abdomen or if you’ve had uh scans of your extremities take a look at fatty infiltration and see where you’re at and you could if you particularly if you changed your diet or change your lifestyle you can measure the impact the interval change how often should we be retesting well I recommend I for my my clients I scan anywhere from 3 to 6 to 9 months I have some clients who will only do it once a year because they have such low levels of atopos either a visceral fat or fat within their skeletal muscle that once a year is adequate for them but I would say for the majority of people you probably want to be doing it um every 3 to six months what is the limitation um one is time takes a little bit of time you got to drive there and go get it get it done as MRI scan of the adom and scanning time is about anywhere 9 to 10 minutes or so um but the cost is uh often times a limitation for other people uh for for a lot of people because that it ranges by state to state it does yeah excellent point so uh MRI in in one location like Los Angeles um they the cheapest I’ve seen about $240 uh some places in Florida where we’re where we’re at today uh you can actually get MRI scans in the Miami area for around $250 uh but then up in my area um couple hours north of where I live that same mrri scan uh cash pay discounted uh will still cost you $2,000 900 for single a difference I know so you you’re better off flying to Miami enjoying the weekend here getting a scan done and then going back to Minnesota right that’s exactly yeah so you should shop around um and I have a course uh some videos um what’s your weite on uh just my uh just my name http://www.d a n m.com Dr sha.com we’ll put it down below as well and and I have a educational Community is just uh uh Dr shauna. podia p o d a.com and so you can join my educational Community where I do a lot of educational videos and courses and things even teaching people how to read their own MRI why because doctors don’t know how to read it they won’t read it and uh so very often if you if you question an MRI you know to to uh uh to look for visceral fat they want even do it so you know you should put it put on indication why you’re requesting MRI say chronic belly pain or diverticular disease or something else because they’ll they won’t do it they Vis fat they you I have one client that actually in Florida it’s a great story he goes he he requests an MRI scan for a visceral fat the front desk approves it the technician goes and does the the downal MRI scan the report shows up with the request for the radiologist now and he goes I don’t know how to read visal fat he goes oh my God you got to cancel this scan give the patient their money back so literally the the client got it all his money back from the MRI scan and uh got a free MRI and of course I I could read it and and the client knows how to read it because it’s follow-up scan and I teach all my clients how to read their own SC so it worked out well for them so just be careful about what you what request is if you if you want to try to get a MRI scan for uh to to look at your visceral fat if you say viscal fat um the doctors are they’re going to they’re going to cancel your request and you’re never going to get your scan there you have it the easiest diet simple steps seven steps here to burn visceral fat follow it and let me know how it works for you and share this episode with a friend if you enjoy this video you’re going to love a recent video I just published on Foods 10 foods that put you in a fat burning State I just discuss a few of them today but there are a few others that I get into in this video check out this clip I’ll see you in that next video there are two types of food that we eat foods that cause weight gain and foods that cause fat loss numerous studies show how beneficial olive oil is not just for your health but for fat loss weight loss resistance insulin resistance and also diabetes the findings showed that the group consuming the olive oil was more effective
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
The source material provides a comprehensive guide to constructing a full-stack AI-powered chat application. It details the technologies employed, including Vue.js and Node.js, TypeScript, OpenAI’s API, Stream Chat, and a Neon Postgres database. The text outlines the development process, from setting up the backend API and frontend UI to implementing real-time chat, AI interactions with context, and database integration for persistent data. Deployment to Render for the backend and Vercel for the frontend is also covered, creating a complete development-to-deployment workflow.
Study Guide: AI-Powered Chat Application
Quiz
Instructions: Answer the following questions in 2-3 sentences each.
What are the primary front-end and back-end technologies used in this chat application project? The front end utilizes Vue.js with Pinia for state management, while the back end is built with Node.js and Express. Both the front end and back end are developed using TypeScript for type safety and enhanced development experience.
Explain the role of the OpenAI API in the Chat AI application. The OpenAI API is crucial for the artificial intelligence capabilities of the application. Specifically, it uses the completions API with the GPT-4 model to process user messages and generate intelligent and context-aware responses, providing the AI-powered chat functionality.
What is Stream Chat, and what aspects of the application does it handle? Stream Chat, provided by getstream.io, is a service used for implementing the real-time chat features of the application. It handles aspects such as messaging, user management, and channels, abstracting away the complexities of building a real-time communication system.
Why is a PostgreSQL database with Neon used in addition to Stream Chat’s features? While Stream Chat stores chat logs, the project sets up its own PostgreSQL database with Neon for persistent storage of users and chat history. Neon offers a serverless, scalable PostgreSQL solution with features like branching, giving the developers more control over their data.
Describe the purpose of Drizzle ORM in this project. Drizzle ORM (Object-Relational Mapper) is used to interact with the PostgreSQL database provided by Neon. It simplifies database operations by allowing developers to work with JavaScript/TypeScript objects instead of writing raw SQL queries, and it’s also used for defining database schemas and running migrations.
What are the key steps involved in setting up the back-end project using Node.js and TypeScript? Setting up the back end involves initializing a Node.js project with npm init, installing necessary dependencies like Express and TypeScript, configuring TypeScript with a tsconfig.json file, and defining scripts in package.json for development, building, and starting the server.
Explain the purpose of environment variables and how they are used in this project. Environment variables are used to store configuration settings such as API keys (for OpenAI, Stream, and Neon) and the database URL, keeping sensitive information separate from the codebase. The dotenv package is used to load these variables from a .env file into the application’s process environment.
Outline the process of registering a new user with Stream Chat in the back end. Registering a user involves creating an instance of the Stream Chat client using API keys, receiving the user’s name and email from the front end, generating a unique user ID (often derived from the email), checking if the user exists in Stream Chat, and if not, using the upsertUser method to create a new user with the provided details.
Describe the flow of a user sending a message and receiving a response from the AI. When a user sends a message, the front end sends it to the back end’s /chat endpoint along with the user ID. The back end retrieves the user’s past messages for context, sends the conversation to the OpenAI API, receives the AI’s response, saves the interaction in the Neon database, and finally sends the AI’s reply back to the front end.
What is the role of Pinia and the pinia-plugin-persistedstate in the front-end application? Pinia is a state management library for Vue.js that helps manage the application’s data in a centralized and reactive way. The pinia-plugin-persistedstate is used to automatically save and reload Pinia stores across page reloads, ensuring that user sessions and other relevant data persist.
Essay Format Questions
Discuss the advantages of using a full-stack approach with technologies like Vue.js, Node.js, TypeScript, and cloud services like OpenAI, Stream, and Neon for building a real-time AI-powered chat application. Consider aspects such as development efficiency, scalability, and maintainability.
Analyze the architectural design of the Chat AI application, focusing on the separation of concerns between the front end, back end, and the various third-party services integrated. Explain how these components interact to deliver the overall functionality.
Evaluate the choice of using Stream Chat for the real-time messaging features versus building a custom solution. Consider the trade-offs in terms of development time, complexity, scalability, and the features provided by Stream Chat.
Explore the process of integrating artificial intelligence into a web application using the OpenAI API. Discuss the steps involved, the role of the API key, the structure of the API requests and responses, and the importance of managing API costs and usage.
Compare and contrast the use of a serverless PostgreSQL database like Neon with a traditional relational database setup. Discuss the benefits and potential drawbacks in the context of a modern web application like the AI-powered chat app, considering factors like scalability, cost, and operational overhead.
Glossary of Key Terms
Full-Stack: Refers to the development of both the front-end (client-side) and the back-end (server-side) components of an application.
AI-Powered Chat App: An application that uses artificial intelligence to understand and respond to user messages in a conversational manner.
Vue.js: A progressive JavaScript framework used for building user interfaces and single-page applications.
Node.js: A JavaScript runtime environment that allows JavaScript to be executed on the server-side.
TypeScript: A statically typed superset of JavaScript that adds optional types, classes, and interfaces to JavaScript.
OpenAI API: A service that provides access to advanced AI models, such as GPT-4, for various tasks including natural language processing and generation.
Stream Chat: A platform that offers SDKs and APIs for building real-time chat, video, and audio functionalities into applications.
Neon Database: A serverless PostgreSQL database platform designed for scalability and developer convenience.
Pinia: A state management library for Vue.js, providing a reactive store for application data.
State Management: The process of managing and organizing the data that drives an application’s user interface.
Express: A minimal and flexible Node.js web application framework, providing a robust set of features for building web and mobile applications.
API Key: A unique identifier used to authenticate and authorize access to an API service, such as OpenAI or Stream.
Completions API (OpenAI): An endpoint in the OpenAI API that generates text based on a given prompt.
GPT-4: A powerful large language model developed by OpenAI, capable of understanding and generating human-like text.
SDK (Software Development Kit): A collection of tools, libraries, documentation, code samples, and processes that allow developers to create software for a specific platform or service.
ORM (Object-Relational Mapper): A programming technique that converts data between incompatible type systems using object-oriented programming languages, simplifying database interactions.
Drizzle ORM: A lightweight and type-safe ORM for TypeScript and JavaScript, used for interacting with SQL databases.
Schema: A blueprint or structure that defines how data is organized within a database, including tables, columns, and their properties.
Migrations: Scripts used to manage changes to a database schema over time, such as creating or altering tables.
Serverless: A cloud computing execution model in which the cloud provider dynamically manages the allocation and provisioning of servers, allowing developers to focus on writing code without worrying about server infrastructure.
Render: A cloud hosting platform used to deploy and host web applications and back-end services.
Vercel: A platform for deploying and hosting front-end web applications and static sites.
vite: A build tool and development server for modern web projects, known for its speed and efficiency.
dotenv: A zero-dependency module that loads environment variables from a .env file into process.env.
CORS (Cross-Origin Resource Sharing): A mechanism that allows restricted resources (e.g., fonts, JavaScript, etc.) on a web page to be requested from another domain outside the domain from which the first resource served.
Middleware: Functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle.
Asynchronous Function: A function that can pause its execution while waiting for an operation to complete (like an API call) without blocking the main thread.
Promise: An object representing the eventual completion (or failure) of an asynchronous operation and its resulting value.
JSON (JavaScript Object Notation): A lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate.
Postman: An API client used to test and interact with HTTP APIs.
Regular Expression: A sequence of characters that define a search pattern, used for matching and manipulating text.
State (Front-end): The data that represents the current condition or mode of the user interface.
Action (State Management): Functions that modify the state in a state management system like Pinia.
Mutation (Implicit in Pinia with Actions): The actual modification of the state in response to an action.
Getter (State Management): Functions that derive computed values from the state without modifying it.
Ref (Vue.js Composition API): A reactive and mutable reference that holds a value, used to track changes in data.
Reactive Variable: A variable whose changes trigger updates in the user interface or other parts of the application.
Component (Front-end): A reusable and self-contained building block of a user interface.
Route (Front-end Routing): A mapping between a URL path and a specific view or component in a single-page application.
Router (Vue Router): The official router for Vue.js, used for navigating between different views or components.
Composition API (Vue.js): A set of additive, function-based APIs that allow flexible composition of component logic.
Options API (Vue.js): The traditional way of structuring Vue.js components using options like data, methods, and computed.
Emit (Component Communication): A mechanism for a child component to send events up to its parent component.
Props (Component Communication): Data passed from a parent component down to its child component.
HTTP Request: A message sent by the client (e.g., a web browser or application) to a server to request a resource or trigger an action.
HTTP Response: A message sent by the server back to the client in response to an HTTP request.
API Endpoint: A specific URL that represents an entry point for accessing resources or functionalities provided by an API.
Context (in AI): The history of previous interactions or information that an AI model uses to understand and respond to the current input more effectively.
Chat History: A record of past messages exchanged between the user and the AI.
Briefing Document: AI-Powered Chat App Development
This document provides a detailed review of the main themes and important ideas presented in the provided source, which outlines the development of a full-stack AI-powered chat application named “Chat AI.” The application utilizes Vue.js and Pinia for the frontend, Node.js and Express for the backend, TypeScript for both, OpenAI’s API (GPT-4) for AI capabilities, Stream Chat for real-time messaging, and Neon Database for a serverless PostgreSQL database. The document includes relevant quotes from the source.
Main Themes
Full-Stack Development: The project encompasses the entire development lifecycle, from setting up the frontend and backend to database integration and deployment.
“hey what’s going on guys so I got a really cool project for you today we’re going to be building a full stack AI powered chat app called chat Ai”
Integration of Multiple Technologies: The application leverages a diverse set of modern technologies for different aspects of its functionality.
AI-Powered Chat: The core functionality revolves around enabling users to interact with an AI for information and conversation.
“we’re going to be building a full stack AI powered chat app called chat Ai”
“for the whole artificial intelligence aspect we’re using the open AI API uh the completions API using gp4”
Real-time Messaging: Stream Chat is employed to handle the real-time aspects of the chat application, including users, channels, and messaging.
“for the whole chat aspect we’re using stream chat at getstream.io so stream offers sdks for powerful applications that Implement real-time chat as well as video and audio”
Serverless Database: Neon Database provides a scalable and easy-to-set-up serverless PostgreSQL solution for storing user data and chat logs.
“we’re going to set up our own database our postgres database with neon so neon offers serverless postgres databases that you can literally set up in like 10 seconds”
DevOps and Deployment: The project covers the deployment process to platform-as-a-service providers.
“at the very end we’re going to deploy the back end is going to go to render … and then the front end The View application will go to versel”
Learning by Doing: The presenter encourages viewers to follow along with the tutorial as the best way to learn.
“I would suggest you follow along with me I think that’s the best way to learn”
Most Important Ideas and Facts
Application Demo: The presenter provides a quick demo showcasing user login (name and email), sending questions to the AI, maintaining conversation context, and saving chat history upon logout and return.
“if I just say simply who was the 12th it’s going to know what I’m talking about”
“if I were to log out or leave the chat and then come back with the same email my chat will be saved”
Technology Stack Breakdown: A detailed list of technologies used on both the frontend and backend is provided.
drizzle is the ORM for PostgreSQL, and drizzle-kit is its CLI.
A tsconfig.json file is configured to specify TypeScript compilation options (ES Modules, target, output directory, source directory, strict mode).
npm scripts are defined for development (dev: tsc –noEmit && tsx watch ./src/server.ts), build (build: tsc), and production start (start: node ./dist/server.js).
A basic Express server is set up in server.ts with middleware for CORS, JSON parsing, and URL-encoded data.
.env file is used to manage environment variables (e.g., PORT).
Initial Git setup with .gitignore (excluding node_modules and .env).
Register User Route (/register-user – POST):Registers a user with Stream Chat.
Expects name and email in the request body.
Uses the Stream Chat client (stream-chat library) initialized with API key and secret from environment variables.
Generates a unique user ID from the email (replacing non-alphanumeric characters with underscores).
Checks if the user exists in Stream Chat using chatClient.queryUsers.
If the user doesn’t exist, it adds the user to Stream Chat using chatClient.upsertUser with the generated ID, name, email, and role (‘user’).
Returns the user ID, name, and email.
Send Message to AI Route (/chat – POST):Handles sending a message to the AI (OpenAI).
Expects message and user ID in the request body.
Initializes the OpenAI client (openai library) with the API key from environment variables.
Verifies if the provided user ID exists in Stream Chat.
Uses the OpenAI Chat Completions API (openai.chat.completions.create) with the gpt-4 model.
Sends an array of messages to OpenAI, including the user’s message with the role ‘user’.
Extracts the AI’s reply from the response (response.choices[0].message.content).
Returns a JSON response with the AI’s reply.
Database Integration (Neon and Drizzle):Installation of drizzle-orm, @neon-database/serverless, and drizzle-kit.
Database configuration in src/config/database.ts using Neon and drizzle, connecting to the database URL from .env.
Schema definition in src/db/schema.ts using pgTable, defining chats and users tables with their respective columns (ID, user ID, message, reply, created at for chats; user ID, name, email, created at for users).
Type inference for insert and select operations using Drizzle.
Drizzle configuration file (drizzle.config.ts) in the root directory, specifying the schema location, migrations folder (./migrations), dialect (‘postgres’), and database URL.
Generating and running migrations using npx drizzle-kit generate and npx drizzle-kit migrate.
Integrating database operations into the /register-user route to save user information in the Neon database after successful Stream Chat registration.
Integrating database operations into the /chat route to save the chat message and AI reply in the Neon database.
Get Messages Route (/get-messages – POST):Retrieves chat history for a specific user from the Neon database.
Expects user ID in the request body.
Uses Drizzle’s db.select().from(chats).where(eq(chats.user_id, userId)) to fetch messages for the given user ID.
Returns an array of messages in the JSON response.
Contextual Conversations: Implementation on the backend to fetch the last 10 messages for a user and include them in the prompt sent to OpenAI, enabling contextual conversations. The chat history is formatted for OpenAI, and the latest user message is added. The role for the AI in the conversation is specified as ‘assistant’.
Frontend Development (Vue.js):Project creation using npx create-vue.
Tailwind CSS setup involving importing tailwindcss in vite.config.js and @tailwind base, @tailwind components, and @tailwind utilities in src/style.css.
Router setup in src/router/index.ts with routes for home (/) and chat (/chat) views.
Pinia store setup in src/stores/user.ts for managing user ID and name with actions to set and clear the user, and persistence enabled.
Home view (src/views/HomeView.vue) with a form for name and email, connected to the backend’s /register-user endpoint using Axios and updating the user store upon success, then redirecting to the chat view.
Header component (src/components/Header.vue) with a logout button that clears the user store and redirects to the homepage.
Chat store (src/stores/chat.ts) using the Composition API to manage chat messages, loading state, and functions to load previous chat history (/get-messages) and send new messages (/chat).
Chat view (src/views/ChatView.vue) displaying messages, handling scrolling, and using a ChatInput component.
Chat input component (src/components/ChatInput.vue) with an input field and a send button, emitting the message to the parent component.
Formatting AI messages in the frontend (formatMessage function using regular expressions) to improve display of lists, bold text, etc., using v-html.
Deployment:Backend deployment to Render: Configuring the build command (npm install && npm run build), start command (node dist/server.js), and environment variables from .env.
Frontend deployment to Vercel: Selecting the Git repository, with automatic build settings (using Vite), and configuring the environment variable VITE_API_URL with the Render backend URL.
This detailed overview captures the comprehensive nature of the project, highlighting the interconnectedness of various technologies to build a modern AI-powered chat application.
Chat AI Application: Overview and Functionality
General App Overview
What is Chat AI? Chat AI is a full-stack AI-powered chat application built to demonstrate how various technologies can be integrated to create a real-time conversational experience with an AI. Users can log in by providing their name and email, engage in chats with an AI, and their chat history is saved and persists across sessions using the same email.
What are the main technologies used in Chat AI? The application utilizes a range of modern web development and AI technologies. On the front end, it employs Vue.js for the user interface and Pinia for state management, both written in TypeScript. The back end is built with Node.js and Express, also using TypeScript. For the AI aspect, it leverages the OpenAI API, specifically the gpt-4 model via the Completions API. Real-time chat functionality is provided by Stream Chat (getstream.io). The application also uses a Neon serverless PostgreSQL database to store user information and chat logs, interacting with it through the Drizzle ORM. Deployment is handled by Render for the back end and Vercel for the front end.
Core Functionality and Features
How does user registration work in Chat AI? User registration in Chat AI is a straightforward process. Users provide their name and email through a form on the front end. This information is sent to the back end, which then registers the user with Stream Chat, assigning them a unique ID derived from their email. Additionally, the user’s ID, name, and email are stored in the Neon PostgreSQL database. No traditional password-based authentication is implemented in this demonstration.
How does Chat AI handle the conversation with the AI? When a user sends a message, the front end transmits the message and the user’s ID to the back end’s /chat endpoint. The back end then retrieves the recent chat history for that user from the Neon database to provide context to the AI. It sends this context, along with the new user message, to the OpenAI API (using the gpt-4 model). The AI’s response is then sent back to the front end and also saved in the Neon database, associated with the user’s ID.
Does Chat AI remember previous messages in a conversation? Yes, Chat AI is designed to maintain context within a conversation. Before sending a new user message to the OpenAI API, the back end fetches the recent chat history for that user from the Neon database. This history, along with the current message, is sent to OpenAI, allowing the AI to consider previous turns in the conversation when generating its response.
How is chat data and user information stored in Chat AI? Chat AI uses a Neon serverless PostgreSQL database to persist data. When a user registers, their user ID (derived from their email), name, and email are stored in a users table. Every message sent by a user and the corresponding AI reply are stored as a record in a chats table, linked to the user by their ID. This ensures that chat history is saved and can be retrieved for ongoing conversations and across user sessions.
Development and Deployment
How are the front end and back end of Chat AI structured? The Chat AI project is structured with a clear separation between the front end and back end. The front end UI, built with Vue.js, resides in a chat-ai-ui folder, while the back end API, using Node.js and Express, is located in a chat-ai-api folder. This separation allows for independent development, testing, and deployment of each part of the application.
How is Chat AI deployed? The back end of Chat AI is deployed using Render. The Render configuration specifies the build command (npm install && npm run build) to compile the TypeScript and the start command (node dist/server.js) to run the server. Environment variables, such as API keys for OpenAI, Stream Chat, and the Neon database URL, are configured in Render. The front end, built with Vue.js, is deployed using Vercel. Vercel automatically handles the build process (vite build) and serves the static assets. The API URL for the back end (the Render-provided URL) is set as an environment variable in Vercel.
Chat AI: Development and Deployment of an AI Chat App
The sources detail the development and deployment of an AI-Powered Chat App called Chat AI. This full-stack application allows users to log in by providing their name and email, and then engage in conversations with an AI. The AI can answer questions and maintain context within a single chat session. User chats are saved, so if a user logs out and returns with the same email, their previous chat history is retained.
Here’s a breakdown of the technologies and functionalities involved:
Functionality:
User Interaction: Users can input text-based questions or statements.
AI Response: The app uses the OpenAI API, specifically the completions API with the GPT-4 model, to generate responses to user input.
Context Management: The backend is designed to retain conversation history within a user’s session, allowing the AI to understand follow-up questions. This is achieved by fetching past messages and including them in the prompt sent to OpenAI.
Chat Interface: The app utilizes Stream Chat from getstream.io to handle the messaging aspect, including users and channels.
Data Persistence: User information and chat logs are stored in a PostgreSQL database hosted on Neon, a serverless platform. The Drizzle ORM is used to interact with this database, manage schemas, and run migrations.
User Registration: When a user enters their name and email, the backend registers this user with Stream Chat and also saves their information in the Neon database. A unique user ID is generated based on the user’s email.
Chat History Retrieval: The backend provides an endpoint to retrieve the chat history for a specific user from the Neon database.
Deployment: The backend, built with Node.js and Express, is deployed to Render. The frontend, built with Vue.js, is deployed to Vercel.
Technologies Used:
Frontend:
Vue.js: A JavaScript framework for building the user interface.
Pinia: For state management on the frontend, allowing for a global store to manage user and chat data. Pinia Persisted State is used to persist the user’s login status across page loads.
TypeScript: Used for type checking on the frontend.
Vite: A build tool and development server for the Vue.js application.
Vue Router: For handling navigation between different views (homepage and chat page).
Axios: An HTTP client for making API requests to the backend.
Tailwind CSS: A utility-first CSS framework for styling the application.
Backend:
Node.js: A JavaScript runtime environment for the backend.
Express: A web application framework for Node.js used to build the API.
TypeScript: Used for type checking on the backend. TSX is used to execute TypeScript code.
CORS: Middleware to enable cross-origin requests between the frontend and backend.
dotenv: To load environment variables from a .env file.
Stream Chat (getstream.io): A platform providing SDKs for implementing real-time chat features. The Node.js client library (stream-chat) is used to interact with Stream Chat’s API for user management and channel creation.
OpenAI API: For the artificial intelligence capabilities, using the openai Node.js client to interact with the completions API and the GPT-4 model.
Neon Database: A serverless PostgreSQL database used for storing user data and chat logs.
Drizzle ORM: A TypeScript ORM used to interact with the PostgreSQL database, define schemas, and perform database operations. Drizzle Kit is used as a CLI for Drizzle to generate migrations.
AI Implementation:
The backend receives user messages and sends them to the OpenAI API using the gpt-4 model.
Previous chat messages for a user are fetched from the database and included in the prompt sent to OpenAI to maintain context. The conversation history is formatted according to the OpenAI API’s requirements, with roles specified as “user” and “assistant”.
The AI’s response is then sent back to the frontend and also stored in the Neon database along with the user’s message.
Chat Implementation:
Stream Chat is used to manage users and create channels for conversations.
When a user registers, they are also registered as a user in Stream Chat.
When a user sends a message, a unique channel is created or retrieved for that user (identified by chat- and their user ID).
Both the user’s message and the AI’s response are sent as messages within this Stream Chat channel.
This project demonstrates a comprehensive approach to building an AI-powered chat application, covering frontend development with Vue.js, backend development with Node.js and Express, integration with AI and chat service providers, database management, and deployment.
Chat AI Application: A Full-Stack Development Example
Based on the sources and our previous discussion about the Chat AI application, full-stack development refers to the process of building a complete web application that encompasses both the frontend (client-side) and the backend (server-side), as well as the database that supports them. A full-stack developer is proficient in working with all these layers of the application.
The development of the Chat AI application serves as a practical example of full-stack development. The project involved building:
The Frontend (Chat AI UI): This is the user interface that users interact with directly in their web browsers. It was built using Vue.js, a JavaScript framework for building user interfaces. Key aspects of the frontend development included:
Creating the user interface with components for the homepage (login/registration) and the chat page.
Managing the application’s state using Pinia. This included managing user information (user ID, name) and chat messages. Pinia Persisted State was used to ensure user login status persists across page reloads.
Handling routing between different pages (homepage and chat) using Vue Router.
Making API calls to the backend using Axios to register users, send messages, and retrieve chat history.
Styling the application using Tailwind CSS, a utility-first CSS framework.
Using TypeScript for type checking to improve code quality and maintainability.
Using Vite as a build tool and development server.
The Backend (Chat AI API): This is the server-side logic that handles requests from the frontend, interacts with the database and external APIs (OpenAI, Stream Chat), and sends responses back to the frontend. It was built using Node.js and Express. Key aspects of the backend development included:
Setting up API endpoints using Express to handle user registration (/register-user), sending chat messages (/chat), and retrieving chat history (/get-messages).
Handling cross-origin requests using CORS to allow communication between the frontend and backend running on different domains.
Loading environment variables using dotenv to manage API keys and database connection strings securely.
Integrating with Stream Chat to manage users and channels for the chat functionality. This involved registering users with Stream Chat and creating unique channels for each user’s AI conversations.
Integrating with the OpenAI API to generate AI responses to user messages using the GPT-4 model. This involved sending user prompts along with conversation history to maintain context.
Interacting with the Neon PostgreSQL database using the Drizzle ORM to store and retrieve user data and chat logs. This included defining database schemas, running migrations using Drizzle Kit, and performing database queries.
Using TypeScript for type checking on the backend, along with TSX for executing TypeScript code.
The Database (Neon PostgreSQL): This is where the application’s data is stored and managed. In the Chat AI project, Neon, a serverless PostgreSQL platform, was used. The database stored user information and the history of conversations between users and the AI. The backend interacted with this database to persist and retrieve data.
Finally, full-stack development also includes deployment, making the application accessible to users over the internet. In the Chat AI project, the frontend was deployed to Vercel, and the backend was deployed to Render.
Therefore, the Chat AI application is a clear example of full-stack development, requiring the integration of various frontend and backend technologies along with a database to deliver a complete and functional user experience.
Chat AI Application: Real-Time Features via Stream Chat
Based on the sources and our conversation history, the Chat AI application incorporates real-time chat features through the use of Stream Chat from getstream.io. The source explicitly states that Stream Chat offers SDKs for powerful applications that implement real-time chat.
Here’s a breakdown of how real-time chat features are relevant to the Chat AI application based on the provided information:
Stream Chat as the Foundation: The application uses Stream Chat to handle the entire messaging aspect. This includes managing users and channels, which are fundamental components of a chat system.
Real-time Capabilities: Stream Chat is designed to provide real-time communication. While the current implementation described in the source focuses on a turn-based interaction with the AI (user sends a message, AI responds), the underlying technology of Stream Chat is capable of supporting more interactive and real-time scenarios if needed.
Abstraction of Complexity: By using Stream Chat, the developers of Chat AI likely leveraged Stream’s SDKs to abstract away the complexities of building a real-time messaging infrastructure from scratch. This includes handling things like message delivery, user presence (if implemented), and channel management.
Backend Integration: The backend of the Chat AI application (built with Node.js and Express) integrates with Stream Chat using Stream’s JavaScript client library (stream-chat). This allows the backend to register users with Stream Chat and create channels for the conversations.
Potential for Expansion: Although the initial version focuses on AI interaction, the use of Stream Chat provides a foundation for potentially adding features like multi-user chat or other real-time communication elements in the future, as Stream Chat also offers video and audio capabilities.
In summary, Stream Chat is the key technology chosen for the Chat AI application to provide robust and scalable real-time chat features, even though the current implementation primarily showcases a single-user interaction with an AI. The use of Stream Chat simplifies the development of the messaging aspects of the application by providing pre-built SDKs and handling the underlying complexities of real-time communication.
Chat AI: Serverless PostgreSQL with Neon
Based on the sources and our conversation history regarding the Chat AI application, a serverless PostgreSQL database is a fully managed database service hosted in the cloud that offers on-demand scaling, automated management, and billing based on actual usage. The Chat AI application utilizes Neon as its serverless PostgreSQL database.
Here’s a breakdown of the discussion around Neon and its role as a serverless Postgres database within the context of the Chat AI project:
Neon as the Chosen Database: The project explicitly states that it uses Neon for its cloud PostgreSQL database. It’s described as offering serverless PostgreSQL databases that can be set up very quickly, “literally in like 10 seconds”.
Key Features and Benefits of Neon (as mentioned in the source):
Easy Setup: Neon allows for a very rapid setup of a PostgreSQL database.
Branching: Neon offers features like database branching, similar to code branching with Git, which is useful for development and testing new features without affecting the main database.
Scalability: It is highlighted as being extremely scalable, implying that it can handle varying workloads automatically without requiring manual intervention.
Data Persistence: The Chat AI application is configured to save user information and chat logs directly in the Neon database.
Cloud-Based: Neon is a cloud postgres database, offering the benefits of cloud infrastructure such as reliability and accessibility.
User-Friendly Interface: Neon provides an easy-to-use interface for setting up and managing databases. This includes the ability to run straight SQL queries directly through the interface.
Integration with the Chat AI Application:
The backend of the Chat AI application connects to the Neon database using a connection string. This connection string, including the database URL and password, is stored as an environment variable (DATABASE_URL) for security and configuration.
The Drizzle ORM is employed to interact with the Neon PostgreSQL database. Drizzle is a TypeScript-based ORM that simplifies database operations.
Drizzle Kit is used as a command-line interface (CLI) for Drizzle to create database schemas and run migrations. The schema, defining the structure of the chats and users tables, is created in TypeScript, and Drizzle Kit uses this schema to generate and apply the necessary SQL to the Neon database.
The backend API includes endpoints to save user data into the users table and store chat logs (user messages and AI replies) in the chats table within the Neon database.
Another API endpoint (/get-messages) retrieves the chat history for a specific user from the Neon database by querying the chats table.
In essence, Neon serves as the persistent data storage layer for the Chat AI application, providing a scalable, easily manageable, and feature-rich PostgreSQL database in a serverless environment. This allows the developers to focus on the application logic rather than managing the underlying database infrastructure. The integration with Drizzle ORM further streamlines database interactions within the TypeScript-based backend.
Cloud Deployment of a Chat AI Application
Based on the sources and our conversation history, the Chat AI application was deployed to the cloud using two separate platforms for the frontend and the backend.
Here’s a breakdown of the deployment process discussed in the source:
Backend Deployment to Render:
The backend, built with Node.js and Express, was deployed to Render (render.com).
The deployment process on Render involved connecting the Render service to the GitHub repository containing the backend code (chat AI API).
Specific build and start commands were configured for the Render deployment:
Build Command: npm install && npm run build. This ensures that the dependencies are installed and the TypeScript code is compiled into JavaScript before running the server.
Start Command: node dist/server.js. This specifies how to start the backend server, pointing to the compiled JavaScript file located in the dist folder.
Environment variables crucial for the backend’s operation were configured in Render. This included the Stream API key and secret, the OpenAI API key, and the Neon database connection URL (DATABASE_URL). These environment variables allow the deployed backend to securely access necessary services and the database.
After configuring these settings, the backend was deployed as a web service on Render. The source mentions that the deployment process can take a few minutes.
Once deployed, Render provides a live URL (domain) for the backend API, which can then be accessed by the frontend. This was verified by making a request to the /get-messages endpoint using Postman and successfully retrieving data from the deployed API.
Frontend Deployment to Vercel:
The frontend, built with Vue.js, was deployed to Vercel.
Similar to the backend, the deployment on Vercel involved connecting the Vercel platform to the GitHub repository containing the frontend code (chat AI UI).
Vercel automatically handles the build process for Vue.js applications, typically using vite build as the build command, although the source indicates that the default settings were largely kept.
An environment variable specific to the frontend, VITE_API_URL, was configured in Vercel. This variable was set to the live URL of the backend API deployed on Render, ensuring that the frontend communicates with the correct backend endpoint in the cloud. The VITE_ prefix is convention for Vite to expose environment variables to the frontend code.
After configuring the API URL, the frontend application was deployed to Vercel. The source notes that the frontend deployment can also take a short amount of time.
Upon successful deployment, Vercel provides a live URL for the frontend application, making it accessible to users via a web browser. The deployed frontend was tested by logging in, initiating a chat, and verifying that it could communicate with the backend and display responses.
In summary, the Chat AI application utilized a microservices-like deployment strategy, with the frontend and backend deployed independently to platforms optimized for their respective technologies. Render was chosen for the Node.js backend, providing a platform for running server-side applications with support for environment variables and custom build/start commands. Vercel was chosen for the Vue.js frontend, offering streamlined deployment for modern web applications with easy configuration of environment variables for API integration. This approach allows for independent scaling and management of the different parts of the full-stack application in the cloud.
Build & Deploy An AI-Powered Chat App | Vue, Node, TypeScript, Open AI, Stream & Neon Database
The Original Text
hey what’s going on guys so I got a really cool project for you today we’re going to be building a full stack AI powered chat app called chat Ai and I’m just going to give you a quick demo before I explain anything so we just log in and and you just have to put your name and email and then we can go ahead and say something we’ll say like um we’ll say who we’ll say who was the 10th president of the US okay so it says AI is thinking and get back the 10th president of the US was John Tyler now it’s going to keep the context so if I just say simply who was the 12th it’s going to know what I’m talking about so the 12th President uh was Zachary Taylor all right and if I were to log out or leave the chat and then come back with the same email my chat will be saved all right now to achieve this we’re going to be using VJs and pinea for State Management on the front end and no. JS and Express on the back end and we’re using typescript on both the front end and backend now there’s a bunch of technologies that we need to incorporate to achieve this for the whole artificial intelligence aspect we’re using the open AI API uh the completions API using gp4 and then for the whole chat aspect we’re using stream chat at getstream.io so stream offers sdks for powerful applications that Implement real-time chat as well as video and audio and and this is just one of the many ways to use stream chat so like I said it’s going to handle the whole messaging aspect the users the channels now even though stream does store your chat logs and stuff we’re going to set up our own database our postgres database with neon so neon offers serverless postgres databases that you can literally set up in like 10 seconds and there’s features like branching it’s extremely scalable and we’re going to set it up so that our our project saves the users and the chats in the neon database and then we’ll be using the drizzle orm to interact with the database uh as well as create schemas run migrations and so on and then at the very end we’re going to deploy the back end is going to go to render so render doc um and then the front end The View application will go to versel all right so this is just an all-in-one Dev to deployment project I have the repositories for both the front end UI and the back backend API in the description so I would suggest you follow along with me I think that’s the best way to learn so let’s jump into it all right so I just want to quickly go over some of the websites where you can find the documentation for different parts of this project so first off we have stream chat which we’ll be using for all the chat aspects and you can find the docs at getstream.io if you go to Developers and we’re using the chat messaging there’s also video and audio capabilities if you want to check that out but if we go to chat messaging there’s all these platforms that we can choose from and we’re using it on the back end so you want to choose the the node.js option and then from here you have all different topics like users tokens permissions um creating channels and all that good stuff so that’s for stream chat and then for neon which is our Cloud postgres database you can go to neon.pdf here and then finally we have openai which is at platform. open.com and this is what we’re using for the whole AI aspect of it and we are going to have to generate API keys for open AI for neon and for stream so you might want to just just keep these websites open so let’s go ahead and just open up a terminal and just navigate to wherever you want to create this project and we’re going to have two separate folders for the back end and front end the back end will be chat AI API and the front end will be chat AI UI that’ll be the vue.js back end will be the node and expr Express so I’m going to put both in a parent folder so let’s create that so I’m going to say make directory and chat Ai and then CD into that chat AI folder and make another directory called chat AI uh- API and that will be our back end and I want to open that up in in vs code so I’m going to say code and then chat AI API and of course if you want to use a a different text editor that’s absolutely fine okay I’m going to be using my integrated terminal so I’ll go ahead and open that up and we just want to run npm in nit of course you need to have no JS installed and let’s go through this so package name version that’s good description let’s say this is going to be a backend for uh we say for an AI chat application and then s uh entry point I’m going to call server say server.js and then author you can put your own name if you want and MIT for the license so type I’m going to be using ES module so we want to put module instead of commonjs I mean if you want to use commonjs you can but um we’ll be using import all right so now that we’ve done that let’s install our dependencies and I just want to quickly go over what our backend dependencies are going to be so we have Express of course which is our backend web framework cores which which allows access to resources from a different origin that’s because our front end and back end will be on different domains EnV allows us to use environment variables from a EnV file stream chat is the official JavaScript client to work with stream chat in nodejs or in JavaScript and then open AI is the client to work with the open AI API typescript we’re going to be using on both the back end and front end a little bit more to the setup in the the back end but it’s not too bad we’re going to be using something called TSX to execute our typescript because even though with node.js version I think 23 um typescript is supported but all it really does is is strip your types it doesn’t actually compile it doesn’t execute it so that’s where TSX comes in if you want to use TS node or something else you can and then drizzle is the OM to interact with our postgis database and then drizzle kit is a CLI for drizzle and we’ll install the drizzle stuff a little later but let’s install some of these dependencies now so let’s say npm install Express we want what else cores we want EnV um stream chat so stream Das chat and also open AI I think that’s I think that’s all I want right now as far as regular dependencies now for for Dev dependencies let’s say npm install D- uppercase D and we want typescript and I’m also going to install TSX to execute the typescript and then for types we’ll do types SL node let’s say at types SL Express and also types slash cores now as far as uh as our typescript config goes we’re going to create our TS conf fig with npx and let’s say TSC D- init and I’m going to open that up and there’s I have a configuration that I’m going to use if you want to use the same one you can just get it from the link in the description the the GitHub repo but I’m going to paste this in so it’s pretty simple we’re going to I want to use es modules and all that all the latest features so using node next for module and module resolution and Es next for the Target our output directory when we compile our typescript is going to be slash and then our root directory where we write our code is going to be SL Source okay we’re using strict mode or strict type checking U and then we’re allowing importing commonjs modules we’re allowing importing of Json files as modules and we’re skipping the Declaration files in the node modules folder to speed up compilation so pretty simple setup we’ll go ahead and save that file and and then we want to create our scripts in package.json so we want a Dev script and of course with our Dev script we want to compile our typescript so we’re going to use TSC so the typescript compiler and then we’re going to add– no emit because we don’t actually want to produce JavaScript files when we run this we’re just running our Dev server and we just want to compile our typescript and we also need to run TSX as well and we’re going to run that in watch mode okay so no need for like node Monon or anything like that and then that’s going to be source and then server. TS will be the entry point so that’s what we want to run okay and then to build our project out to just compile we want to run just TSC and then the start script so to run in production is just going to be node and then it’ll be in a disc folder and it’ll be called server.js so that’s all we need for uh for our npm scripts all right so now let’s create a folder in the rout called Source that’s where we will write all of our code and let’s create our entry point which is going to be server. TS I mean if you don’t want to use typescript that’s fine we’re not doing too much as far as typescript goes so even if you’re not familiar with it you should be all right Honestly though it’s really becoming the standard so I mean you’re going to be creating TS files and TSX files all the time so I mean I would suggest learning the basics of typescript if you don’t know it so let’s just create a basic Express server so we want to import Express from Express and we want to import uh let’s see we want to import cores as well and we also want to import EnV and then we want to call env. config and then we’ll initialize our Express app so set that to express okay we need have some middleware to add so cores requires us to add an app.use and we’re also going to do app.use express. Json because we want to be able to um when we send a request we want to be able to send Json in the body we also want to be able to send form data so let’s also do app.use and say Express and then URL encoded and then just pass in an object with extended and set that to false all right and then we want to create our Port variable and I’m going to set the port in the EnV so I’ll say process. env. port or then use 5000 and then let’s just uh take our app and let’s listen on that Port whoops listen on Port and then when that happens we’ll just run a console.log and put in some btics here and we’ll say the server server running on and then output that Port variable all right so let’s um let’s create ourv so that’s going to go in the rout not in the source folder and from here we’ll say port and for now I’m just going to set it to 8,000 because I want to make sure that it’s actually reading this value so down at the bottom here at the terminal or wherever your terminal is let’s run npm run Dev okay so server running on 8,000 and it’ll compile any typescript we have obviously we don’t have any right now and before we start to add our route I just want to make my my first commit so I’m going to open up a new terminal here and let’s run and get a knit and then we’ll create our do get ignore uh CU you definitely don’t want to push thatv so let’s add not node modules and Dot EnV all right so I’ll say get add all get commit oh what’s this don’t care get commit and we’ll just say initial Express setup set up our initial Express and TS setup all right so now what we want to do is have make our first route and what this is going to do is it’s going to reach out to to stream chat and it’s going to register a user with stream okay because you can actually log into to your stream dashboard and you can see the users that were registered for um what is this doing here for your for your application and it when I say register it’s not traditional authentication where you’re going to have a password and stuff basically you come to the the app and you put in your name and email and then from there you get sent to the you know the the form to interact with the AI so let’s start by just creating a route now since we’re using typescript we’re also going to bring in from Express we want to bring in uh request and response uppercase R and let’s create our first route we’ll go down here let’s say I’ll put a comment let’s say register user with stream chat and it’s going to be a post request so app post and for the endpoint we’ll call this excuse me we’ll say SL register D user and then we’re going to have an async function here okay and then as far as what this returns will be a promise and we’re just going to add any to this and then it’s going to take in the request and response and we want to set those to those types so request and then res which will be response and then just to test it I’ll do a res. send and we’ll just say test okay so now we have our first endpoint now as far as how you test your endpoints it’s it’s really up to you I I like to use Postman and I have the postman extension for vs code so if I click on this icon right here I can make a a new HTTP request and it just opens up in a new tab which is nice so I’m going to make a post request to http and we want Local Host and I have it running on 8,000 and we want to do register Das user and you’ll see I get a 200 response and I get test so we know that that that route is working we also want to send an a name and email so why don’t we do a little bit of validation here we’ll say if or first of all let’s get the name and email so that’ll be in the request body so let’s say cons and then we’ll destructure the name and email from requestbody and then we’ll say if not name or not email then we want to send back an error so so we’ll return res Dot and let’s do a status of 400 which is a user error and then we’ll attach the Json uh let’s just put an error here and we’ll say name name and email are required and then after the if I’ll just do a res. status say 200 and Json message success all right so let’s try that out so if I just send as is I get the error but if I send a name and email in the body I can either do Json data or I can use the form URL encoded so I’m just going to add name and email and then send and I get success all right so now we want to start to work with stream we installed that you should have the stream client so if you just look in your dependencies you should have stream chat that’s what we’re going to use now in order to create an instance we have to we we need our API key so we’re going to have to go to the getstream.io and just you can log in with with either GitHub or Google so I’m already logged in I’m going to go to my dashboard and you don’t have to pay anything or enter any credit card info for this we want to create a new app and this has to be unique so I’m just going to say chat Dash uh we’ll say chat Ai and I’ll just do das Brad you could put your own name whatever it just it has to be unique and then just choose the locations for the the chat and video storage and feed storage that’s closest to you and click create app and then you’ll have your keys right here we have a key and a secret we need both of these so I’m going to copy the key I’m going to go into myv and we’re going to add stream API key and set that to the key and then we also want the stream API secret which we can get from right here just going to copy that okay so I’ll paste that in now that we have that we should be able to create an instance so let’s bring in the library so import or the client and that’s called stream chat and then we’re going to create it or initialize it right above our row let’s say initialize initialize the stream stream chat or stream client so we’ll say const we’ll call this chat client and I’m going to set that to the the stream chat stream chat Dot and then it’s get instance and then that’s going to take in your API key and your API secret so let’s say process Dov Dot and then stream API key and I’m going to put a bang on the end of this which is a nonnull assertion so I’m basically telling typescript that this is it’s not going to be null or undefined it’s definitely there and then we’ll do the same with the secret that gets passed in as well okay so now we should have our chat client initialize now we can use it in our route and the first thing I want to do is is create an ID because when you create a user it needs to have a unique ID and it’s up to you on what you want that ID to be I mean you could install a package like uuid but what I want to do is take the email you don’t have to type this out but let’s say that the email is Brad gmail.com then I want the ID to be brador gmailcom so that way we have a unique ID but it’s also readable it’s understandable all right so let’s um let’s do that so I actually want to after we do the if here let’s wrap this in a TR catch and I’ll move this this success I’m going to move that into the try and then let’s copy it and then in the catch if something goes wrong then I’m going to send a 500 error so let’s change the status to 500 and for the message we’ll just say or it’s actually going to be error so error we’ll say internal server error all right now in the try let’s generate the ID so we want to say user ID and we have access to the email that they enter so we’re going to use replace and replace takes in it’ll take in what we want to replace and what we want to replace it with so and we pass in a regular expression I know a lot of you guys and including myself hate regular Expressions but this is pretty simple so in Brackets we’re going to use the uh the carrot so basically we’re saying if not if it doesn’t match whatever I type here which is going to be a lowercase A to Z so a low lowercase letter or an uppercase A to Z or 0 to9 or an underscore or a dash if it’s anything other than that I want to replace it with an underscore and I want this I want it to be Global so I’m going to put SLG so the second argument you pass in is what you want to replace it with which in our case is going to be an underscore okay so that’ll generate the user ID in fact we can go ahead and do a console log of user ID just to check and then if I make a request again with this Brad at Gmail and I send if we look down in the console brador gmailcom and again if you want to do something different for IDs you can so yeah let’s get rid of the console log and now I want to check to see if the user exists in stream chat so let’s say check if user exists and we can do that let’s put this in user response and this is a synchronous so we want to do await and then chat client and then there’s a method called query users so we want to use that and then what we can do is pass in an object where we want to match the ID and we set that to an object with this money sign EQ so we’re saying if it equals the user ID and we can do a console log of that as well and then just go ahead and send and if we look down here you see it gives us an object with a duration and the user’s array which is empty because that the user doesn’t exist that um in my case it would be the Brad gmailcom doesn’t exist so what we can do after that after we check if the user exists or after we set that variable we’ll say if not user response. users. length so we’re saying if that array is empty then we want to add new user to stream so we can do that with the uh there’s a few different methods we can use I’m going to use upsert user which will create or update a user so let’s say chat client. upsert we want to do it’s just a single user so upsert user and then we’re going to pass in an object I’m going to assign the ID to the user ID which will be that formatted email the name set that to name and the email and then I’m also going to add the role of user because there’s there’s different roles there’s an admin user as well in fact if we look at the the docs here if I search for roll permissions let’s see yeah so right here buil-in roles so user is a default user role you have guest um you have admin which is a role for users that can perform administrative tasks with elevated permissions so we just want a a regular user now I should also mention that this is where you you can also generate a token so let’s see um we could call right here create token however we’re we’re using this on the server side with an API key so we don’t need to do this but if you were using this from you know react or view or some kind of front end then you would want to create a token and you’d want to save that and then send that with your um you know the rest of your requests so but we don’t have to do that so yeah I just want to return now basically just return the user ID the name and the email so let’s go right under that if actually we already have this we might as well just use that um yeah we’ll get rid of the message and let’s send the user ID the name and email and I think that should do it so we can try it out now so I’m going to come back here I’m going to register the user Brad gmail.com let’s click Send and I get back a 200 I get back my that’s my user id formatted from my email my name and the actual email now you should be able to actually log into your dashboard so if I go to my chat AI app here and under chat messaging if I go to Explorer you can see I have my chat AI Brad app has an app ID app name if I click users I got Brad 90 not sure where that came from but right here is the the user that I just created and it has all these fields it has the ID the name language role created at updated that if the user banned if they’re online if they’re invisible so lots of information uh and you can delete users too in fact I’ll delete that Brad 90 user oh it’s an original dashboard user okay so I can’t delete that all right so we’re able to to register users now for the chat and later on we’re also going to implement our neon postgres database so that it saves users there as well and it also saves all the chats all the logs but before we do that let’s create our chat route chat route so that we can send a question or or whatever it is we want to send to the AI and use the open AI API to respond to that so let’s first of all bring in the open AI client so up at the top here we’ll say import and it’s going to be open AI from open Ai and then we need to initialize open AI here as well just like we did with stream so right here I’ll say initialize open AI now we are going to need an API key so why don’t we do that real quick I’m going to jump over to platform. openai and log in so from here if we click on settings go to API Keys you should see them here um I’ll just create a new one let’s say chat and for project I’ll just use um project one okay so I’m going to copy that and then I’m going to go ahead and add that to myv so here let’s say opencore AI uh actually no let’s do open AI underscore and then API uncore key and then set that okay so now what we can do is initialize here let’s say const open a excuse me open AI set that to new uppercase o Open Ai and then pass in our API key which is going to be process.env do open aore API key okay so that’ll initialize that now let’s create our our chat route so I’m going to go under the register user and let’s say um what should I say here let’s say send message to Ai and this is going to be a post request as well so app post and the route is going to be just slash chat and then let’s say async okay I’m going to return say promise and any and then we’re going to pass in the request and res response all right so the first thing I want to do is get from the body there should be a message and there should be the user ID because when you register a user you get the ID and then you’re going to send that along to the chat route so let’s say const and let’s get the message and the user ID from the request. body and then we want to just make sure that that exists so we’ll say if not message or not user ID then we’re going to want to return let’s say status 400 and Json we’ll say message and user are required all right then we’re going to go under that if statement and let’s open up a TR catch and in the catch we’re going to I’ll just copy this response here except we’re going to change this to a 500 and then for the error for the error we’ll just say internal server error and in the try first thing we’re going to do is let’s say verify user exists so we’ll say const user response we want to set that to a wait on the chat client and then we’re going to use Query query users pass in an object we want the ID to match the user ID okay after we do that let’s check that response we’ll say if not user response remember it has an array called users so we’re going to check that we’re going to check the length and basically if it’s an empty array then we know the user isn’t hasn’t been found it doesn’t exist so let’s return res. status and four we’ll do 404 because it’s a not the user’s not found and then we’ll we’ll do Json and let’s pass in an error and for the error we’ll say user not found and we’ll say please register first all right now before we do anything else let’s just let’s just check if that works so we’ll just do a simple res. send and just say success okay so when we make our request now to slash chat it should reach out to stream and uh in the body I don’t have uh I don’t have anything so I should get this message and user are required so let’s add in the message I’m going to say what is the capital of Massachusetts and then for the user ID for the user ID I’m going to put a user that doesn’t exist I’ll just do one two three and if I send that I get user not found please register first now we know that the user ID for me brador gmailcom we know that that exists so let’s try that out and we get success so so far so good now what we want to do is start to work with open Ai and we’re going to use the chat completions API which will work like chat GPT you send it a prompt and it sends you a response so let’s go right here where I have the res. send and delete that and let’s send the message to open Ai and we’re going to be using the gp4 model so we’ll say con response and set that to await open AI and it’s going to be chat dot completions Dot and then create and then we want to pass in an object that has the model that we want to use which in this case is going to be GPT you have all these different options we’re going to do gp-4 so that’s the model we want and then we send messages which is going to be an array and we’re going to pass in an object here with a rle of the user and then the content is going to be the message all right so whatever we add in the message which in my request is just what’s the capital of Massachusetts now I want to show you what that gives us so why don’t we just do a console log of the response and then as far as what we return I’ll just let’s just do uh yeah we’ll just say res. send success okay I just want to see what what this gives us so let’s come back over here and I’m going to send the same response with the message and the correct user ID we get success but let’s take a look in the in the console here and we get this object has an ID blah blah blah what we care about is this right here this a choices array and there’s an one object in there with a message and we can’t see it here we just see object um yeah I don’t think we can see that so why don’t we log that so we got console log response and then it’s going to be dot choices which is an array we want the first and only item in that array and we want the message okay let’s send it again and there we go so we get an object with the role is assistant okay so it’s the the AI That’s responding has a role of assistant and then content is what we’re looking for the capital of Massachusetts is Boston all right so it’s as easy as that to to create a prompt and get back a response so now obviously we want to return that response from the endpoint so let’s come back in here we know how to access it now right with this it’s actually message. content that will give us the exact you you know what we’re looking for so let’s get rid of the console log here around this and let’s put this into a variable we’ll say const AI message and um let’s type that it’s going to be a string and set it to that so response choices message content now I am going to use um optional chaining here for for uh message so just add a question mark there and then we also want to use a nullish coalescing operator because if that happens to be null or whatever then we’re just going to make it no response from AI that’ll get rid of any typescript errors now before we actually send this AI message back from this endpoint we need to create a channel which is used for managing conversations in fact if we go to the docs here and we search for Channel and then creating channels so it shows us how to do that we store a reference in a variable using our client and then. channel pass in the type which is going to be messaging okay there’s different types if we come down here and look at type you have um live stream messaging team gaming Commerce messaging is is for like you know one-on-one conversations or group chats um that’s uh typical type for things like that and we’re having a one-on-one chat with it’s just not with a user it’s with the AI so that’s what we’re going to use and then once we store the reference we can then call channel. create and then we can actually do channel. send message as well which will send the message through through the channel it’ll get stored and so on so let’s um let’s do that let’s go right below the AI message and let’s say actually I’m going to just put a comment here let’s say create channel or it’s actually create or get channel and we’re going to create the reference with our chat client. channel the type is going to be messaging and we can also pass in a unique ID which I’m going to use back ticks and then just say chat Dash and then the um the user ID so that’ll be a unique identifier and then we want to pass in an object with the name of the channel which I’m going to call we’ll call it AI chat and then we also need to add this created uncore byor ID which if you were chatting with another user then it would be that user but since we’re using an AI we’re going to call it AI bot all right so that will will create the reference now we need to call channel. create like I just showed you in the docs and then after that we can do uh sorry this needs a wait and then after that we can do await channel. send message and pass in an object with the text which will be the AI message so AI message and then the user ID and make sure you do user uncore ID that’s what the key is it’s not camel case it’s underscore and then that’s going to be the AI bot that sends this message okay now as far as what we want to respond with let’s do res. J actually we’ll do status 200. Json and then pass in um an object oops passing an object with a reply and that reply will be the AI AI message oops not Al message AI okay so yeah that should do it and then I just want to do a console log here as well if there is an error let’s put um error generating AI response and then also the error all right cool so let’s try that out I’m going to come over here and I have I have my message I have my user id let’s go ahead and send and we get an object with the reply the capital of Massachusetts is Boston and what’s cool is now if we go back to the stream dashboard and if we go to you know chat messaging Explorer we have the AI bot user here and you can see under channels we have messaging so it’s that’s the type and then we have the unique identifier which is chat D Brad Gmail com because I set that right here right that’s the unique identifier and then we should be able to see any messages that are in through that channel so we have one message here and it shows the text which is the capital of Massachusetts is Boston so whatever the AI sent us back so pretty cool now what I’d like to do is Implement our own database I mean we do have the the you know you can see the chats and using stuff through stream but a lot of times you want to do more with it so you’ll want to store the chat logs in your own database so I want to expand this to to do that and also store our users so you want to create uh a postgres database through neon so I’m going to go ahead and log in here all right and then we’re going to go to well yeah I guess we’ll create a new project so once you log in and this interface is is so easy to use and it’s so easy to set up a database it’s basically just a couple clicks so I do want to create a new project I’ll call this uh tutorial and you can choose your postr G version I’m going to stick with 17 your database name I’m going to call this chat chat Aid DB and I’ll just choose AWS and then create and you can do a lot from this interface I mean you can run straight SQL queries there’s branching so just like you have branching with GitHub with your code you have branching with your databases so if you want to whatever add a new feature and you don’t want to affect the main branch you can just create a new Branch work with that once that’s all set and you know that’s what you want to use then you can merge the branches so really cool and what we want to do now is just click connect and that will give us our connection string so right here we want to copy this and actually let’s click show password too and then copy and we want to store that that uh reference to the the database the database string in ourv so let’s go in there and let’s call this database uncore URL and go ahead and paste that in all right right so now that we have that we need a way to interact with our database and that’s where drizzle comes in drizzle is an OM it’s typescript base it’s really easy to use um but one thing we do have to do since we’re using neon is use the neon database serverless adapter so we do have to install that as well so let’s come down to the terminal here and let’s run npm install and we want drizzle Das omm and then we also want to install at neon database SL serverless okay so it just allows us to to use um drizzle and to use this with with uh neon’s infrastructure and then we also want to install drizzle kit as a a Dev dependency so let’s say npm install Das uppercase D and then drizzle dkit and this is a CLI and we can run migrations from it and stuff okay so now that those are installed a couple things we have to do a few files we need to create so one is going to be our database config file which I’m going to put in the source folder I’ll create a new folder called config and then in that config we’ll have a database. TS file and this is where we configure That Neon database adapter so let’s go ahead and import a couple things here first one is going to be Neon and that’s going to be from this right here neon database SLS serverless then we want drizzle so import drizzle and let’s see we’re going to bring that in from drizzle omm and then it’s going to be slash neon HTTP and then we want to bring in from the dotv package we want to bring in the config function because we’re going to be using environment variables so let’s go ahead and load environment variables and we do that by calling config and then since I have this in you know in the source folder than in the config folder I’m just going to specify the path to the EnV file you can do that by passing in an object like this just say the path and it’s justv because it’s in the root okay cuz that’s going to start in the root all right then we just want to check for the database URL so if not process. env. database uncore URL then let’s throw a new error and we’ll say database uncore URL is undefined okay so we got that um next thing we want to initialize the neon client so actually going to put a comment here so init the neon client and we’re going to put that in a variable called SQL so we set that to Neon and that’s going to get passed in the database URL so process. EnV do database URL and then we need to initialize drizzle and that’s going to be exported because we’re going to be using this in other files so we’re going to call this uh variable of DB and then we set that to drizzle and that gets passed in the SQL variable which is the neon client so we can close that file up and now we want to create our schema and if you’ve used like Mongoose or SQL eyes or Prisma we create a a model or a schema of our data and then we can use drizzle kit to run the migration looking at that schema and it will create the tables for us so I’m going to put this um in let’s see we’ll have in the source folder I’ll have a folder called DB and then in DB will have a schema. TS file all right so let’s start off by importing what we need from drizzle so we need PG table which is going to create post postres tables for us and that’s going to come in from drizzle o/ PG core so in addition to that any Fields any field types that you want to use you bring in here so for instance serial which is what our primary key IDs are going to be and then text and then timestamp I believe those are the only ones we need so what we do now is export for any any table we want to create we export uh uh PG table function that takes in the name of the table and then all the fields we want to use so for instance for the chats let’s say const chats and we want to set that to PG table and the name of the table will be chats and then we pass in an object with all the fields that we want so for instance the ID is Going to Be A Serial type serial field and that’s going to be named ID and then I want that to be the primary key so we can tack on do primary key next thing we want is the user ID so that’s going to be text and user undor ID uh and then let’s see we’re that’s going to also be not null so we’ll tack that on then we have the message so let’s say message of the chat and this will be message as well then we want the reply which will be the you know the message that’s sent back from um from the the AI so that’ll be text as well and reply and not null all right and then the last thing I want here is created at so created at is going to be a Tim stamp and that’s going to also be called Crea underscore uh at and let’s add on to that I’m going to use default now which will do the current time stamp and that should also be any parenthesis there that should also be not null all right so that’s our our chats now let’s do the users because I want to store users as well so we’ll say con users not exports so cons user set that to um PG table and the name of the table will also be users and then we want to pass in all of our Fields so first thing is going to be the user ID which will be text and user ID for the column name and this is going to be the primary key so we want to add that all right then we get the name so name will be text as well name for the column name and not null all right then we got email so let’s change this and this to email and then we want a created at so I’m just going to copy this one because it’s the same thing okay so that those are the two schemas and the two tables we want to create now drizzle is is really great when it comes to typescript we can have our type inference in inference for drizzle queries so basically when we insert a chat for instance it’s going to be structured in a specific way with a specific type and we can add that here the type inference for the chat insert for the chat select for the user insert and for the user select so we want to export the so we can use them outside of this file and we’re going to say type and then chat insert and we want to set that to type of and then chats and we want this infer insert okay money sign infer insert and then we want to do the same for the chat select which is going to be infer select and change this to chat select okay and then we want to do the same thing for users so what I’ll do is just uh whoops what I’ll do is just grab both of these and copy those down and then we’re going to change this first one here to user insert and make sure we change this to users and then this one here change that to users and this one is going to be users select like that okay so that takes care of the type inference for those types for insert and selects now we want to create a config file for for drizzle or for drizzle kit because it needs to know where the scheme is are it needs to know um where the migrations will go things like that so that this is going to go in the root because that’s where it looks so in the root not in the source but in the root we’re going to create a drizzle. config dots all right and we want to import let’s see we’re going to be using EnV so we want to bring in the config from that so that’s going to be from EnV and then we’re going to import Define config and that’s going to come from drizzle kit and then let’s just run uh let’s say config because we’re going to be using the environment variables to get the database URL and again I’m just going to specify path and it’s just in the root. the EnV okay and then we want to export as default Define config and then that’s going to get passed in a couple things so first is going to be schema and that’s going to point to what we just created which is going to be from the root in the source folder and then in the DB and then schema schema. TS okay so that’s our schema um then we have out so this is going to be the migrations folder so just uh it’s going to be slash migrations all right then we have the dialect so dialect I mean you can use drizzle with different databases MySQL Etc we’re using postgres in fact you can see the options here so we’re going to use postgres and then the for the DB credentials that that’s going to be an object and we just need to provide the URL which is going to be our process uh process. env. database URL and let’s just add a bang on the end of that all right so that’s our config so we can close that up now since that drizzle config is in the root directory we are probably going to have an issue with typescript because it’s compiling the The Source folder right so we can run into an issue there so what we can do is exclude that file so under compiler options right so it ends right here so under compile options we’re going to add exclude and it’s going to be an array and we just want to add in that file so we want uh drizzle what is it drizzle. config dotx yes and that just cleared up that error that was there okay so now we have our schema created so that means that we’re ready to create our migration and when we create our migration we first generate it and then we we do drizzle kit generate and then drizzle kit migrate and that should actually create our tables for US based on this based on the schema so let’s try that let’s come down here and let’s run or we need npx and drizzle dkit and then we want to do generate first okay so your your SQL migration file so it created that here and then and you’ll see there’s a migrations folder here now then to actually migrate we want to do npx drizzle kit migrate all right so let’s see you can only connect to remote super B instances through web socket not exactly sure why it’s saying that it is a warning so let’s go to our neon dashboard and let’s check it out so if we go to tables and we have our chats yep chats table you can see the fields here ID user ID message and we have our users table okay so that worked I’m not exactly sure can only connect to remote neon versel postgress through a web socket um I guess I’m just not going to worry about that right now because it did work it created our tables from our schema which is what should have happened so now let’s integrate the database into our endpoints into the register user and into the chats because again we want to save the users we want to save the chats actually let’s bring in up top what we need to First okay so we’re going to import we want our DB right so DB which is going to come from our database now this is something that I want to mention when you’re using typescript with node with with TSX and you have the configuration that we do when you import a file because this is the first file that we’ve imported the rest have just been you know package modules so you it says JS even though it’s a TS file okay you can’t do import TS that’s not going to work it’s going to give you an error so even though it says JS everything to do with typescript compilation everything is just it still works fine this is just the syntax we have to use so in addition to that we want to bring in our schemas so chats and users and that’s going to come in from slash DB and then slash schema and again we’re going to do schema JS even though it’s a TS file and then let’s see what else do we need um there’s a utility called EQ to to basically compare values to compare the users and so on so that’s going to be EQ from drizzle omm and then what else do we have here uh the oh the chat completion message pram type so we’re going to bring that in as well so chat completion I don’t see it here completion message right here so that’s going to come from openai resources MJS actually we don’t need the MJS I don’t think yeah that should work okay so now that we we have our Imports let’s figure out where we actually want to use the database so we have our register user right so that creates a user with stream but again we want to also save the users in our own database so I’m going to go down right above the the response okay after we deal with all the stream stuff and let’s check for existing user in the database I know we checked for if it’s in stream but we also want to check in our own database so let’s say const existing user and I’m just going to close that up and we want to set that to a wait and this is where use the DB right so DB from our config file database config and then I’m going to call a few different methods on this one is Select so I want to select from the users table where so do where this is just the syntax of drizzle which I I like pretty clean so where now this is where we use that EQ utility so we want to pass in EQ and we want to see where users do user ID is equal to the user ID okay and that the user ID would be you know what we create from the email when a user is registered so it’s going to check for that and well it’s going to put it in this variable now let’s come down under it and let’s say if not existing user uh we’ll say if not existing user. length then let’s just um we’ll first off we’ll just do a console log and I’ll put some back ticks in here and we’ll say user and then the user ID uh we’ll say does not exist in the database and we’ll say adding them because that’s what we’re going to do all right so under that line let’s await DB and then we’re going to call insert and we want to insert into users where values okay so the values we want to add pass in an object here with the user ID the name and the email all right and that should be it so let’s save it now and I’m going to come back to uh to postman so let’s send a request so I’m going to make a post request to http we want to do register user and in the body for form data let’s add a name and an email okay so I’m going to go ahead and send that all right so I get back what I’m supposed to to now we want to check the database so let’s go to uh to Neon just going to reload this and there’s the user so user ID which is also the primary key the name email and the created ad so now not only are we do we have the users in the chat Explorer and stream we have it in our own database which we can do whatever we want with right and I had deleted the the user before so there it is again all right so in addition to the users in the database we also want to store the chats so let’s go back to server TS and let’s go down to the chat endpoint and figure out where we want to use the database here so let’s see we’re getting the user response here right then we check the user response so let’s go right under that and we’ll say check check user in database so again we’re going to do const actually I can just copy the the line of code I just put here okay so we’ll add that here and then um actually we can take what we put after that too which is this except we’re not going to create the user so we do have to change that so right under where we check the user let’s paste that and uh we’re going to get rid of this insert we don’t want to do that and then for the actually we’re not even going to do a console log we want to return an error if the user isn’t there so let’s say return and then res. status and we’ll do uh 404 and let’s do Json error and we’ll set the error we’ll say user not found in database please register first okay so we’re making it so that if the user isn’t in our postres database our neon database then it’s still it’s not going to let it happen right it has the user has to exist in stream and it has to exist in our database so now let’s go under where we get the AI message message and store that and let’s say save we’ll say save chat to database so to do that we can just say await db. insert we want to insert into the chats or the chats U table and then for values we’re going to add the user ID we want the message the reply uh actually reply we’re going to set that to AI message okay so we’re just taking whatever this is right and we’re just storing it as reply and that’s it so now we can try that out so I’m going to come over here and let’s go let’s make a request to slash chat and we’re going to change the stuff here so let’s say message and let’s do something different um Let’s do let’s do something a little more difficult like create a simple let’s see what should we do we’ll say create a simple rest API with python so that’s our message and then for the user ID I’m going to put my user which is going to be brador gmailcom so let’s try that out and it might take a couple seconds obviously the the more difficult the the answer the longer it’s going to take okay so we got our reply and it has a bunch of you know new line characters and stuff for formatting and we’ll we’ll when we create our UI with view we’ll have this displaying nicely so here’s a simple example on how to create a rest API using flask a microweb web framework in Python and it goes through and gives us the steps all right so we know that’s working now let’s make sure that that got saved to the database so we’ll go to Neon and I’m going to go to chats and there it is message create a simple rest API reply there’s the reply now since we implemented a database I’d like to add one more route to to get the messages of a specific user okay and we’re going to need that for our UI because obviously when you’re you know sending messages as a user you only want your messages so let’s create a new route we’re going to come down here and let’s say we want to get chat history for a user so app. poost and let’s see the the endpoint is going to be SLG get- messages and we want to do a sync return promise any okay I’ll pass in here our request so request Andre which will be response all right so what I’m going to do first is get it’s going to take a user ID so we’ll destructure the user ID from request. body because that needs to be sent with the body and then let’s check for the user ID or check if not you user ID and if not then we’re going to return res. status and we’ll do 400 and we’ll pass in an error and say user ID is required all right so if the user ID is there then let’s open up a try catch and let’s create a variable here we’ll call it chat history so chat history and then we want to await DB and then we’re going to select I’m going to go on the next line here so db. select and from okay we want to select from chats and let’s say where so where and we’re going to use EQ here CU we’re comparing so we want to to say where the chats. user ID is equal to the user ID and then we’re going to return actually we can just do res res. status 200. Json and let’s pass in we’ll do messages messages and set that to the chat history okay and then if there’s an error then we’re going to res. status 500 and let’s uh we’ll pass in an error and we’ll say internal server error and then I do want to just do a a console log as well so we’ll say um actually let’s do quotes and say error fetching chat history and we’ll output the error okay so that’s our get messages so let’s try that out I’m going to come over here post request to SLG get- messages and then we just want the user ID in the body so I’m going to go ahead and send and now it gives me back an array and you see we have id1 user ID message and then the apply I should have my other one here actually no I deleted the other one so let’s make another um let’s do another chat and then for the message make sure we check that let’s say what is the most popular JS framework send as of 20 okay so the 2021 is the cut off for this um it says the most popular JavaScript framework is react all right so now if I were to go back to get Dash messages with the user ID I should have both so create a simple rest API and what is the most popular JS framework okay so we have three routes we can we register a user we use that user to to chat to ask a question to the AI and then we have a an endpoint to to get all the messages of a specific user so that’s pretty much it as far as the back end there there’s a couple things later on while we’re doing the front end that I want to add to the back end but I think that I’ll be able to explain it better once we have the UI and I know that backend development like this can be a little tricky and can be a little weird because you don’t you’re not looking at like a user interface for your are the results of what you’re doing you’re just seeing a bunch of data so it can be can be tough for for some people so um if you if you’ve been confused through this don’t worry about it I mean it happens as you do more of it it’ll kind of Click but now what I’d like to do is jump into the front end create a whole new folder for our our chat AI UI and start to use vuejs okay so now we’re going to get into our front end and like I said we’re going to be using vue.js version three um we’re going to be using a couple other dependencies so let me just show you those real quick so view we’re using vit for our Dev server and environment we’re using pinf for our state management Library so we’ll be able to create a store for our users for our chats uh we’ll be able to have our actions and our state in those stores axios I’m using for my HTP Library although if you want to use fetch that’s fine too really doesn’t matter it’s just preference and then Tailwind CSS I’m using for The Styling so we will be be adding quite a bit of Tailwind classes to make it look nice view router we’re using the official router for view uh and we’re just going to have two routes two pages one is going to be the homepage with the form that has the email and the name so that you can you know enter your name to start chatting and then of course the chat route chat page where you interact with the AI and then typescript which we don’t have to set up at all it just works out of the box with vit so those are our frontend dependencies now I have the backend running so you definitely want to have that um this is just something I was testing out but you can see it’s mine’s running on Port 8000 and then I’m going to go into the chat AI folder and you can see I have the the back end that’s what’s running over here I want to create a folder alongside of this in my chat AI folder not inside the API folder that’s the back end this is completely separ separate so alongside that let’s go ahead and run npx and then I’m going to use create V and let’s call this chat D ai- UI okay this is the user interface part of our application and then we’re going to choose view I’m going to choose typescript although if you you want to use JavaScript that’s fine too and I mean even if you don’t know typescript it’s we’re not doing that much so you should be fine and and we already used it in the back end um and it’s much easier to set up I mean there really is no setup in the front end it just works so now let’s go ahead and CD into chat ai- UI and then let’s run our npm npm install to install our initial dependencies that come with v and then we’ll install a couple other dependencies as well all right so let’s go npm install and view- router we want pinf for our state management and there’s also a plugin called uh persisted State and we want to use this because we want our state our user to persist across page loads so we’re going to install pinea Das plugin Das persisted State and then also axios so those are our front end those are our regular dependencies and then for Dev dependencies it’s just tailwind and the plug-in for V for Tailwind so let’s do Dash uppercase D and then Tailwind CSS and then also at uh what is it at Tailwind CSS SLV and Tailwind version 4 is super easy to get set up with v okay so now that we have our dependency set up I’m going to actually just open this folder up in vs code and I’m going to run the dev server from the integrated terminal so from here let’s say NP say npm run Dev and it’s going to be 5173 for the port by default and I’m just going to make this going to just bring this over here make this a little smaller okay so this is just a landing page we’re going to get rid of the the boiler plate um what I do want to do is set up Tailwind which is really easy we just need to go into our V config first and we’re going to import uh Tailwind CSS from and then it’s going to be this at tailwind cssv and then we just need to add the plugin to the array here so Tailwind CSS parentheses and then the only other thing we need to do is go into our main stylesheet so in the source folder I want to go into style CSS and we can get rid of all this other stuff and just simply do at import and then in quotes take Tailwind CSS and that’s it and you can see Tailwinds working because there’s it’s all the same font size there’s no padding or or margin on the body so Tailwind is working all right now let’s just clear this up a little bit I don’t want the hello world component so we can completely delete that okay and then in the app. view we don’t want that I’ll leave the script tag there and then in the template uh actually we can get rid of this the scope style and then in the template for now let’s just have oops let’s just have an H1 and we’ll just say my app okay so just kind of clear everything out and in the assets we don’t need the view SVG you can get rid of that now I do have a little robot icon and logo that I want to use so let me just find that real quick you guys can get this from the the GitHub repository that that’s in the description let me just find it real quick uh let’s see Dev I’m just trying to find it off screen where we chat AI UI all right so it’s going to be in you have the fabicon which is in the root so just bring that over to your root and then you have um in the source assets folder there’s a robot PNG you’re going to bring that into your assets folder so it’s just this little robot guy all right now to add the fabcon we can go into the index HTML in our um in the root and I’m just going to change the page title to let’s do chat Ai and then for the fabicon we’ll just add a link and let’s change the real to Icon We’ll add a type of image slash it’s an Ico and then slash favicon Ico and then you should see the little robot in the tab all right so right off the bat I just want to set up routing okay because we’re using view router we’re going to have the home route we’re going to have a chat route so let’s start by creating those pages or those views so in the source we’re going to create a folder called views and then in there we’re going to create a file file called home let’s call it home view. viw Vue and then let’s create another file called chat view. viw okay and then I’m just going to have a script tag and then we’re going to add our setup so as far as vuejs goes this is not an intro to view I’m not going to explain the the basics um I have a view course A View crash course on YouTube that I just did it like a couple months ago so it’s really up to date if you don’t know anything or you know very little about VJs I would suggest watching that I mean you can watch it after if you want so you can kind of understand what you did but I would suggest watching it before but basically with the composition API which is a kind of a more Modern Way of of building view components you basically have to have in your script you would export uh a setup function right and then you do all your JavaScript all your state stuff you would do in here but you can do a shortcut by just adding setup here that’s why I’m doing that and then I’m also just going to add Lang and since I’m using typescript I’m going to add Lang TS and then I’m not even going to put anything in there for now then we have our template so basically the HTML we want to show on this in this component or in this page which right now I don’t really care we’ll just do an H1 and we’ll just say chat or chat page all right and then for the home view I’m just going to grab that and we’ll just change this to homepage all right because I I just want to get these created so that we can create set up our router so we can close those up for now and then for the router we’re going to have a folder in the source folder called router and then in that will have a file called index.ts and this is where we set up our routes now to do that we need to import a couple things so first off we need create router from view router and then we also want a function called create web history which allows us to use the the HTML 5 history API to to do routing instead of you know actual page loads and then we also want to bring in any views or any components that we want to load so that would be the home View and that would be the chat view okay then what then what we do is create an array for our routes so we’ll set that to an array and each route will have an object with a a path so in this case I want this to be just slash for the homepage and then we can load a component which our views are our components so let’s set that to the home View all right and then we’ll do the same thing for the chat view so let’s make this slash chat and this will be for the component chat view then what we want to do is export const router so this is what we bring into other files and this is where we want to set this to create router which is going to take in an object with history and we want to set that to the create web history again that’s going to use the the HTML 5 history API and that’s a function so you want your parenthesis and then you just want to pass in your routes as well all right and that’s it for that file now couple other things we need to do before we can actually use our router we need to initialize it in the main.ts file which is basically our entry point so in this file uh let’s see we’re going to bring in let’s bring in in and we want create router uh I’m sorry not create router just router we already used that in our router file that we just created and that’s what we’re bringing in here so router from. SL router now we have to use that so where we have this create app which bootstraps the entire application it mounts it to this this element with app um I’m going to just put this in a variable and then we’ll mount it down below so we’ll take this and we’ll do app. Mount here instead and that way we can take that app that app object and we can call use and then we can use the router okay so we got that done now the last thing to be able to see the routes on the page in the main app. view where we have this H1 we want to replace that with router View save that and now we see homepage because we’re on the the Home Route if I go to SL chat then we’re on the chat page and if you want to create just a quick navigation we can do nav and then we can use router link okay so router link we can add a two attribute here to slash and then we’ll have one to chat slash chat and then we should be able to click on chat takes us to the chat page home takes us to the the homepage now we do need to set up our store but before we do that let’s just get the form displayed on the hom page uh and we can get rid of this nav we don’t need that okay so let’s go into Let’s see we want to go into the home View and I’m going to bring in the that robot image because that’s going to be our logo so let’s import robot image from and then it’s going to be dot dot slass assets slash and then robot.png okay so we’ll bring that in and then let’s just start to add some of the the elements down here and use our Tailwind classes so we’re going to have a div that wraps everything get rid of this um div and then for classes here we’re going to do h- screen let’s make this a flex box and align everything to the center so items Das Center and justify Center I’m not going to explain what every Tailwind class does I have Tailwind crash courses I have a premium course if you want that but it’s pretty obvious what most of these classes do background we’re going to make gray let’s do 900 for the shade and then we’re going to do text white okay so that just gives us this dark background then inside that I’m going to have another div with a class of pad let’s do padding 8 and I’m going to do BG gray 800 make get a little lighter and rounded large let’s do shadow shadow large and let’s make it width Dash full and a Max width of medium all right whoops I don’t know what what happened oh need to do this all right so there’s our container for the form so in that div let’s have an H1 we’ll do text Dash let’s do 2XL for the sizing we’ll say font Das semibold let’s do uh margin bottom four and text Center and in that we’ll say welcome to chat AI all right oh I forgot the robot so let’s actually put above the the H1 I’m gonna have my image now since the source is going to be pointed to a variable right it’s Dynamic we need to bind it so we could either do a v-h on or we can just put a colon here and then set it to something Dynamic such as the robot image variable and then I’m just going to add a couple classes on this as well so let’s do MX so margin on the X Access Auto width 24 height 24 and then let’s do a margin bottom four and there we go so now I have the little robot guy and then let’s go under the H1 and we want to have our inputs so for the classes here we’re going to do Dash uh with Dash full let’s do padding two for margin bottom two and then I’m going to do a BG gray 700 so make it a little lighter the text will be white um let’s say round rounded Das large and then I’m also going to add a focus style so on Focus I want outline Das none okay uh yeah and then let’s add a couple other things so in addition to whoops what did I do here that should be there so I want to add a placeholder and it’s going to say name and then we want to buy this name to uh a reactive variable we want to we want to have a a piece of component State called name and we do that with v- model and we we’ll set that to name and we want to create that name variable up top here in the script so let’s say con name and we set that to ref okay we’re creating a reactive value so ref and then whatever the default is will go in here which is going to be an empty string now that ref we do have to import that from view so let’s bring that in that should be lowercase R okay there we go so now that gets bound to that if I put in you know hello here it’s going to show here because that is bound to that input okay and then we’ll have some other values here as well like the the uh email and let’s see do I want to add the rest of the stuff now um yeah uh might as well just copy this down so we’re going to have a loading state so basically when we reach out to our API we’re going to set loading to true and then when we get the result it’ll be set to back to false so let’s set this to ref default value will be false um and then I also want for ER if we have an error I want to have that in our state as well that’ll just be an empty string by default as well and then let’s come back down let’s create our email input so I’m going to take this copy it down let’s change the type to email and let’s see we’ll change placeholder to email and the V model to email so now this input is going to pertain or is going to be bound to this variable if I save it we see the email and then let’s create the button okay so right here let’s say say button and as far as classes go let’s do with- full let’s do padding to we’ll do BG blue Das 500 and rounded large all right and inside that I want it to say start chat but if it’s loading then I want it to show logging in okay and it’s not actually a login but you know what I mean creating the user or just getting the user so if you want to show something Dynamic uh within your view template you use double curly braces so here I can put a JavaScript expression like if it’s loading then show logging in dot dot dot else then show start chat so now we have our start chat button and then I also want to make this button disabled if loading is true so it’s going to be um Dynamic so I’m going to do colon disabled because what I’m setting this to is a is a variable right it’s loading so if I were to set loading up here I know a lot of you guys know this stuff but for those of you that are kind of new to view if I set that now it’s disabled and it says logging in so I’ll set that back to false all right now let’s see um for the error I want to show that down here in a paragraph So in the paragraph we can use a v if directive which is just like an if statement whatever I put in here in here will only show if this is true so for V if we just want to set that to error so if error is true then I just want to show the actual error and we’ll just add a class uh let’s add a class of text Dash red we’ll do red 400 and text Center and let’s do margin top two okay so if I have an error which we can test out by just putting something in here then it will show like that all right cool now that button is going to call a function so let’s go to the button here we’ll say at click so when we click this we’re going to call call a function called create user which doesn’t exist yet so we’re going to go up here and we want to create we want to create the create user function so here let’s say const create user we’ll set that to async an async function and let’s let’s check for the the name and email so we’ll say if not name and we can access the value with DOT value or if not email. value okay so if either one of those are not you know not added then I want to set an error so we’ll say error. value and we’ll set that to let’s say name and email are required and then we’ll just return okay and then I think you know what what I think that’s as far as I want to go because we don’t have our store yet cuz what we’re going to do is send a request to well we could you know what we’ll send the request I’m trying to think of how I want how the order I want to do this in do we want to do the store first yeah you know what before we do the request let’s do the store I mean we can test out this little validation if I were to click Start chat without putting anything then it’s going to give us an error but yeah let’s create our store so so basically when the data comes back from SL register user from our back end it’s going to be stored in our user store which we have yet to create so we’re using pinea which means we have to initialize it so we’re going to go into our main.ts which is right here and couple things we need to do um yeah we’ll go right here and let’s import here create pinea from pinea and then we also need that plugin which is pinea plugin persisted State that’s going to come from oops it’s going to come from uh this right here okay so we want to bring those in and then let’s go above this app let’s say const pinea set that to the create pinea function and then we should be able to take that pinea object and say do use and we can use the plugin so pinea plugin persisted State we want to pass that in and then the only other thing we need to do is use it just like we did the router so copy that down and pass in pinea okay I don’t have the code right in front of me but I’m pretty sure that’s that’s right all right so we’ll close that up now to create our store let’s go into the source folder create a folder called stores and for each resource we’ll have a file so I want to create a file called user. TS so this is where our Global State goes as well as any actions which are going to be functions that mutate the state in some way um so what we’re going to do is import Define store and that’s going to be from pinea all right and then we’re going to export let’s export const and we’re going to call this use user store and we want to set that to that defined store and then that’s going to take in a name of our of our store so user and then we pass in an object and this is where we can Define our state which is going to be set to an arrow function and some and it’s going to be set to an OB it’s going to return an object in that object we’re going to have our user ID and we’re using typescript so I’m going to say null as string or null so what we’re doing is using a type assertion and we’re defining it as null to begin with but we’re saying it can be null or string and then we’re going to do the same thing with the name okay so if you remember when we hit that register user route it sends back the user ID the name and the email we don’t need the email um in the the the project so I’m not going to store it in the in the store if you want to you can but I’m just going to leave it out for now so in addition to our state we want to have our actions so let’s put a comma here and then actions and actions is an object with functions in it to manipulate the state in some way so let’s create a function called set user and set user is going to take in a data object so for the type it’s going to be an object that has a user ID which will be a string and also name which will be a string and we can a access this right these values in our state we can access with this keyword so we can say this. user ID is going to be set to the user ID that’s passed in here uh I’m sorry it’s going to be be data. user ID okay and then we’ll do the same thing with the name so this set that so this.name is going to equal data. name then let’s go under set user because we also want to have a log out because we need we need a way to clear this state so here we’ll say this. user ID is equal to null and then this do name is equal to null and then the last thing we’re going to do is persist the state meaning that it’s going to the user will stay even if the page refreshes or reloads so we’re going to go right here put a comma and we can add in here persist and we’re just going to set that to true and I’ll put a little comment here and just say keep user logged in across um across page reloads and that yeah that should do it so that’s our user store and we’ll have a chat store later on so now let’s go back to our home View and we’re going to import the we want to import the use user store that we just created that’s going to be from and then dot dot slash stores sluser okay and then we’re going to be redirecting the user as well so we’re also going to import use router from view router now we have to initialize these two things so right here let’s say const user so user store set that to uh use user store um why is that oh it’s just I just haven’t used it right yeah okay so then also the router so let’s say cons router set that to use router all right now we have access to the user store so let’s make our request down here in the create user so after this if statement let’s first off set the loading value and set that to true because we’re now loading because we’re we’re making a request and let’s just make sure the error value is clear and then I’m going to use a tri catch for the request now for as far as the URL that we make the request to for me it’s going to be HTTP Local Host 8000 but when you go into production obviously that’s going to change so we should put that in an environment variable so let’s go into the root not the source but in the root and let’s create a EnV and here we’re going to say vit under so these are going to be prefixed with vit and then API URL and we’ll set that to http Local Host 8000 if you ran it on a different port make sure you put that all right so that way we can just have one central place for that URL now let’s make the request and I’m using axios by the way so I have to import that as well uh let’s see so import axios and then let’s say const I’m going to destructure the data if you’re using fetch then you would do that here but I’m going to await on axios.com API URL okay so that’s where we want to go and then slash so after the the closing curly brace SL register Das ususer so we’re making a request to our backend now we also want to pass in after that backtick uh a comma and then we want to pass in the data that we’re sending which is going to be our name and we remember we access that with name. value and then email so this will be email email. value and then once we do that we can then set the this the user data in our store to the data that we get back okay so let’s do that we’re going to say user store and then we’re going to call our set user action we’re going to pass in the user ID set that to the data. userid and then we want to do the same thing with the name so this will be name oops name and then it’ll be data. name okay so we’re setting it to our store and then the last thing we want to do in the try is just redirect so router. push and we want to go to slash chat and then in the catch let’s do uh we’ll say error. value and set that to we’ll just say something went wrong and we’ll say please try again okay uh let’s see did I set this oh you know what this let’s make this e r r because we can’t have that being error and the state being error error all right and then we want to set the loading to false no matter what whether it’s an error or not so we can add a finally so right here finally and then we’ll set the loading do value to false okay so that should do it right so again just to kind of reiterate we click the button it calls create user and checks the name and value inputs sets loading to true then we make our request to our backend which we already created send the name and email we get back the user ID the name and email and we’re storing the user ID and the name in our state right in our frontend UI State then we’re just redirecting to chat and we’re setting loading back to false so let’s try this out uh I’m going to come over here I’m just going to refresh the page here and then let’s do like I’ll say John Doe or just John and John gmail.com start chat says logging in redirects me to the chat page right now I should be able to check I can check this in a few places I can check stream or I can check um uh neon so we’ll do both going to go back here to my Explorer and stream and if we look look at users you’ll see right here John gmailcom so that’s what that’s who I just registered as right and then if we go to our neon console and go to users John gmailcom so now our front end is connecting to our backend sending a request signing up with both you know setting it in stream sending it to our own database so that we have our own uh store of users for what whatever you want to do with them um sets a channel and that’s it now what we need to do is create this chat page so that we can interact with the AI however before we do that I’d like to have a header at the top because we do need um we do need a way to log out I say log out but it’s not actual authentication but you know what I mean just make the user know right the user ID and the email so let’s create a component we’re we going to go into the components folder and let’s create a header. viw file okay and we’re going to add our script let’s add our setup so setup and for the Lang set that to TS and then we’ll have our template okay so in our template I’m going to have a div with padding y let’s do py4 px-6 BG Das gray 800 let’s do Shadow DMD make this a flex box we want to justify uh justify between and let’s do items Das Center all right so within that div I’m going to have the robot image which I need to bring in so up here just close that up so up here let’s import that so import robot image and that’s going to be from dot dot SL assets SL robot.png all right so for the source I’m going to just add a colon here since this is a dynamic variable it’s a robot image and let’s see just a couple classes on this so so class is going to be W so width d8 and height -8 and we’ll just say for the alt chat AI now we want to bring this header in uh it’s not finished yet but I just want to be able to see it so it’s only going to be on the chat page it doesn’t have to be on the homepage so we’re not going to put it in you know the main app file we’ll put it right in chat so in the chat view let’s go ahead and import header and let’s see we’ll just get rid of this uh H1 here I do want to have a div though with just a couple classes so let’s do Flex I’m going to do flex-all h- screen BG let’s do gray 900 and text- white and then in that we’ll put our header and there we go so looks pretty good so back to let’s see home view we can close up but back in the header let’s finish this up I’m going to put under the image here an H1 with a class of text large and font semibold and we’ll say AI or chat AI now it’s way it’s way over on the right because I have justify between so all the spaces in between but I’m going to put a log out button so this will be pushed over into the middle and the log out button will be on the end so let’s add button and I’m going to do text Gray 400 and also on Hover so hover will make text- white and inside of it will’ll say log out okay so there’s that now when we click it let’s go ahead and add an event handler so we want to click so when we click it’s going to call a function called logout now the log out function is the action in the store right if I go to my user store we have this log out action so we can bring this into to our our header and use it so up at the top here let’s let’s import and whenever you want to use the user store you need to bring in use user store all right so we’re bringing that in um I’m also going to bring the the user use router in so use router from view router and then we need to initialize both of those so let’s say const use or user store set that to use use user store and then let’s say cons router set that to use router and then for the log out uh what we’re going to do is if it first calls a logout function here so we’ll create that and then from there we want to then take the user store and we want to call the logout action and we can do that just simply by doing Dot user store. logout then we just want to redirect so router. push and we want to redirect to the homepage the home view okay so when we call that log out it’s going to clear the state because again in our user store it’s going to set the user ID and the name to nulls so when we log in we hit our backend we get the data back it sets it when we log out it clears it so let’s do it let’s say log out and now there we go so now we want to do the the chat right we want to be able to actually interact with the AI so I’m going to log back in as John so I should be able to just do John on at gmail we want to work on getting the the messages which right now John is a new account so he doesn’t have any so I’m just going to add some so I’m going to go to my to postman or open whatever HTTP client you want let’s make a post request to chat and then in the body you want to include your user ID which for me is going to be johore gmailcom that should be lowercase ID and then we want to send a message and for the message I’ll just say what is the capital of um say Maine and let’s send okay so capital of main is Augusta let’s send another another message here what do I want to ask it um say what is the what is the most popular programming language curious to see what it says oh most popular language is Javascript however it’s very it it may vary based on the specific industry or use case Python and Java are also widely used all right so we have uh some chats now so we want to get these and we want those to display here so what I’m going to do is create a new store for chats so in stores let’s create a file called chat. TS now you can set your store up in different ways in the user store we use the object style where we have a state you know State we have an object with State action and uh just any other options but we can also use the composition API and we can use reactive variables with ref like we did in our components so that’s what I’m going to do with chat the chat store because it’s a little more complicated so let’s start off by importing Define store okay so we want to bring that in from paa and then let’s also import ref because I’m going to be using reactive variables that’ll be from View and then I’m going to bring in axios because I’m also going to do the the fetch from here or the HTTP request and then let’s do what else we also want the user store okay because we’re going to need the user ID the the user that’s logged in so let’s say use user store bring that in from do/ user all right now we’re going to be formatting our chat messages a certain way so meaning the message that we send as well as the message we get back and I’m going to use an interface for that okay so this is a typescript interface and it’s basically just like a type where we Define certain fields that it has to match so let’s call this chat message and chat message has to have a message which is going to be a stream Str and has to have a reply which will be a string so that’s our chat message let’s do another interface of formatted message and formatted message is going to have a role because when we get our messages back we need to know which which one is the the user and which one is the AI so the role is going to be a string of either user or AI okay it has to be one of those and then we’ll have the content which will be either the message or the reply so that’s going to be a string so those are our interfaces and you could put those in separate files if you want but there’s only two Fields so I’ll just keep them here and then let’s export const and let’s say use chat store just like we did use user store set that to our Define store which is going to take in the name which which we’ll call chat and then we’ll have our function yeah actually this yeah we don’t want an object here you can use an object like we did in the use uh user the user store but I’m going to have a function and we can use the composition API here so let’s create a variable for messages and set that to ref so it’s going to be a reactive variable and I’m going to use typescript generics here to Define what a message should be which is going to have a roll which will be a string and content which will be a string and it’s going to be an array messages so we also want to have after the curly brace here our brackets and uh ref is a function so we want to have our parentheses and the default value goes in here which is an empty array okay and then the other thing that I want to have is is loading and and set that to ref which is going to be false by default then we want to initialize our user store because we need that user ID so let’s say const user store and set that to use use user store right and then we need to have a function that will load previous chat messages so let’s say load previous chat messages and we’ll call this load chat history and this is going to be asynchronous okay and first thing I’m going to do here is check for the the user the user ID so we’ll say if the user store do user ID or rather we want to say if not the user ID then we just want to return okay then we’re going to open up a try catch and we want to make our request and the the end point we’re making the request to is get messages right because we want to get our messages so let’s say const and we’re going to destructure the data from axios so let’s say await axios Dot and it’s going to be a post request and then we have our API URL which is in the the EnV file so let’s use some back ticks here and we’ll say um to access that we can do import. meta Dov and then Vore apiurl and then outside of the curly brace we want to do SLG get- messages okay so we’re going to hit that endpoint and then we want to pass in an object because we need to send the user ID with it to get the user’s messages so it’s a user ID and then user store. user ID all right and then uh let’s see so the way that the messages come back right in fact we can just we can just check this out so if I say new new request and I want to hit I want post and then the get messages and in the body I’m going to add my user id which is johore gmailcom if I do that I get back my messages the me the two that I just sent right so it comes back in an array called messages and then an object that has ID user ID message reply created at where message is what I sent reply is what the a sent now I want to I want to manipulate this data into basically into an array that has the role which will be either the AI or the user and the content which will be either the message or the reply based on if it’s the AI or the user right we want to match this right here so this this interface so we have to uh basically map through and and return an array with those two Fields um and we also have to flatten it because what we what we can do by using map right if we map through we can get like an array with the the roll so it would be like user and then content would be just whatever right and then we’d have another array like that and we don’t want that we want we want an array that has objects in it like this so we want to flatten it so the the method we can use to do that is called flat map okay which is just a JavaScript method so that’s what we’re going to do we’re going to come down here and we’re going to take messages which is our reactive variable that we set up above and I want to set the value of it it right so value and I want to set it to the data. messages which comes back which looks like this initially it’s going to look like this an array of of those objects so on this we want to run our DOT our flat map just going to go on the next line here so let’s say um flat map and then that takes in a function and for this we’re going to say MSG so for each message which is going to be formatted as the chat message interface and then what that’ll return so right here we want to put a colon and what that’ll return is a formatted message array okay that has that matches this right here the U the role and the content okay so it gets passed in the chat message we want it to return the formatted message and the way we do that um actually we just want to set this right to an array and pass in an object and say roll so roll user and then the content will be the MSG Dot and then message because we the me remember what we’re getting back here the message field is the user what the user says the reply is what the AI says so we want to do that and then let’s copy that down and then the rooll for AI will be the reply so MSG do reply and then I want to just filter filter it because all I want is the content that’s what we want to show right is the message and the replies which is now going to be in content we don’t want to show the ruler so the ruler the role so I’m going to filter that out so let’s go on the next line and say filter and pass in uh let’s say MSG so MSG which will now be the formatted message okay no brackets because it’s not an array we’re we’re going through each one so each one will be a formatted message and we just want to return from that we want to filter out just the content which will be the reply or the me and the message and then for the error so in the catch here let’s just do a console do error and we’ll say error loading chat history and then show show the error Okay cool so we have our chat store and we have our load chat history so now we want to call this right we want to call this within our um chat view so let’s go to chat View and we want to bring in couple things here so up at the top let’s import now we want this to happen when the component mounts and we can do that by using on mounted so I’m going to bring in on mounted I’m also going to bring in a function called Next tick and what that does is it allows us to wait until the Dom finishes loading before it does something so we’re going to do that and that’s going to both of those are going to be from View and then we want to bring in both stores so let’s say use user store and then we also want to import the use chat store and while we’re at it let’s bring in use router from view router and I think that should do it for now now we need to initialize a couple things so the user store set that to use user store then we have the chat store set that to use chat store and then the router so const uh router set that to use router and then I want to make sure that the user is logged in so uh let’s just say Ure user is logged in and again I know I’ve said this but if you want to incorporate actual authentication with a password you can do that but I didn’t really want to focus on authentication because that’s you know that’s such a huge thing I wanted to focus on the whole AI aspect of it so yeah let’s just check if not so if not user store. userid then we’re just going to take the router and we’re going to push to slash and then I also want to scroll to the bottom right so because we’re going to be able to scroll through the chats I want it to to scroll to the bottom so let’s say autoc scroll to bottom so I’m going to create a function here called scroll to bottom all right and then in that um this is where we’re going to we’re going to use next tick which again we’ll wait until the Dom has been updated and that takes in a function and then to scroll to the bottom let’s get the chat container which we haven’t created yet we don’t have that you know down in the output but we will so we’ll say chat container and we’re going to set that to document. getet element by D and it’s going to have an ID of chat Dash container okay so then under that I’m going to just check for chat container and then we’ll take chat container and we’re going to set the scroll Top Value to the scroll height so chat container. scroll height okay now like I said when when we the component mounts right we come to the page the component mounts that’s when we want to call the load chat history that we just created in the store so let’s go under that scroll to bottom and let’s say on mounted okay so this is how we use this we just pass in a function and then we’re going to call chat store and then load chat history which returns a promise so I’ll just use a DOT then um and then we want to scroll to the bottom so scroll to bottom like that all right and let’s see why is this does not exist on type store did I not save it um oh I didn’t return this oh so at the bottom here we want want to return an object and we’re going to return the messages the is loading the load chat history and that’s it for now okay good so now that error should go away now we want to add the output so let’s go right under the header and I’ll say chat messages so we’re going to have an ID of chat Dash container and let’s add a couple classes here as well so for classes we’re going to do Flex das1 let’s say overflow on the Y AIS Auto let’s do padding so P4 and space- y-4 now in here we’re going to have a div with a V4 so the V4 attribute will allow you to Loop over something in our case the the chat messages and output um elements based on you know on those messages so let’s have um let’s do a div I’m just going to add a class of flex onto this and then items Dash start okay so on this div I’m going to add a v-4 directive and set that to the way we do this is open up some parentheses and say MSG so MSG we can also get the index in and then whatever we want to Loop over which is going to be this the chat store. messages so we Loop over those we also need to add a unique key so let’s bind so colon key and we’re going to use the index as the key and then uh let’s see we’re going to add we’re going to have some we’re going to have a a conditional class because if it’s a user I want to align it a certain way and if it’s a AI I want to align it a certain way so the way we do that is in addition to class we can do colon class to make this Dynamic and then we can put basically a JavaScript expression in here I’m going to say if the message. roll if that is equal to user then I want to add add the class of justify Das end else I want to add the class of justify Dash start okay so that’ll add some conditional styling and then inside that div we’re going to have another div and let’s do a class of we’ll say Max let’s do Max with uh extra small so Xs and I’m going to do p padding on the xaxis 4 padding on the Y I 2 and let’s do rounded large and then I also just want to add on medium screens and up then let’s do a Max width of medium okay and then I want this to have a conditional class as well because I want to have a different color based on if it’s the user or the AI so just like we did above we’re going to do colon class for conditional uh styling and let’s say If the message. roll is equal to user then I’m going to have the class BG Das blue- 600 with text- white else then I’m going to have the class of BG Das gray- 700 and text- white and then let’s put in here we want the content so MSG do content which will be either the reply if it’s the ai’s message or message if it’s the user’s message okay so hopefully that makes sense um yeah let’s go ahead and try that there we go so looks pretty good what’s the capital main capital main is Augusta it’s the most popular programming language gives us the answer cool now the next step is to be able to actually ask something because right now we’re just seeing the messages that are there so let’s go back to our chat store and we’re going to have a new function to do this so let’s see we’re going to go under this one and let’s say send new message to Ai and we’re going to create a function called send message set that to async and it’s going to take in a message which is going to be a string okay then in our function I’m going to check for let’s say if we’ll say if not message and I’m just going to add trim onto that to trim the whites space or not user store. userid then we want to return okay so if there’s no message or if there’s no user then we just want to return then we’re going to take our messages right so messages is our reactive value up here right so our messages and I want to push onto that so let’s say messages. value. push I want to add to that an array not an array an object with a rle of user because it’s coming from the user and then the content of message okay okay and then this is where we’re going to use that is loading so I’m going to set is loading to True okay because uh actually that needs to be is is loading. value set that to true because we’re about to make our request all right so let’s add a try catch and in the try we’re going to make our request so we’ll destructure the data from await axios dopost and the endpoint we’re hitting is the chat endpoint so let’s do our back ticks and then we’re going to add the import. meta Dov we want the Vore API URL and then slash chat so that’s the end point and then we want to pass in the data that we want to send which is going to be the message and the user ID which is going to be set from the user store. userid okay now let’s come down here and let’s take the messages value and push on to that and this time it’s going to be the role of AI because this is the response right so role is going to be Ai and then content is going to be the data dot in the rep reply CU again the it’s going to look like well this is get messages but when we send a chat it it’s formatted the same way basically all right so we do that and then in the error let’s let’s just return a message we’ll have a message but it’ll just say like unable to process so let’s take our messages and let’s well first off you know what let’s let’s just console. error and we’ll say error Sending message and we’ll put the error okay and then as far as the messages go let’s say value. push and we’re going to pass in an object with the role which is going to be Ai and then the content which will say error unable to process request okay and we want to set the is loading to false so for that we can add a finally and then we’ll set is loading the dot value set that to false and then we want to make sure that we return the um send message okay so now ready to use that so let’s go back to our chat View and let’s see we’re going to go so we got our message content and we want to go under under the second closing div here and we’re going to have uh a div let’s do Flex so flex and justify Dash start and then this is going to have an if because I want to check for that loading state so let’s say a vif and set that to chat store Dot and then is loading okay so if it’s loading then I just want it to say AI the AI is thinking so let’s actually put a div with a a background we’ll do gray 700 and text- white PX4 py 2 and let’s do rounded large okay and then in that div we’ll have a span and I’m going to use the animate Das pulse class and we’ll say ai ai is thinking dot dot dot okay so that’s if it’s loading and then we want to put the input the chat input uh under Let’s see we got one two 2 three so just above the last div is where I want to put the chat input now I want this to be in its own component so let’s uh let’s do that let’s create a new component in the components folder and we’ll call this chat input. view okay and then we’re going to add our script and our setup and our Lang of TS okay and we’re going to import we’re going to import ref from View and I want to set a message variable here so let’s say cons message set that to ref it’s going to be empty by default and then we have to send this up a level right because we’re embedding the chat input component into the chat View and we need the message to be sent up so we need to emit it so we’re going to say const Emit and the way we do this is we can use Define emits and then we’re going to pass in an array and it’s going to be called send Okay um now here we want to have our send message and set that to an arrow function okay and then that’s what we’re going to call when we submit the input put so before we do that let’s create our output our template so in our template we’ll have a class of padding padding four let’s do BG Das gray 800 and flex and then in that div we’re going to have our input add a couple classes here Flex one padding to rounded large uh BG gray 700 text white and then I want to have a focus class as well so at the end here we’ll say Focus colon and I just don’t want to have an outline so outline none all right and then in this input we’re going to bind it to that message variable so we use V model for that so V model to message and then we’ll add a placeholder as well so say send a message make that lowercase so send a message and then I want to be able to call the send message function when we hit enter with we’re going to have a button too but I also want to be able to hit enter so I’m going to add here let’s say at and then we can do key up and the key that I want is enter so we can just say do enter and then set that to send message all right and then underneath the input just going to put a slash there so underneath the input we’ll have the button so here let’s say button and give it some classes margin left we’ll do margin left two PX -4 py2 I’m going to do a color of BG blue 500 and rounded large okay and the button will just say send and of course when we click this we want it to call send message so let’s say at click set that to send message all right and that should do it now we just have to add our send message here and all we really need to do is emit the the message up to the to the chat view so let’s first off check we’ll say if not if not message. value and then we’ll just trim it so if not message then we want to return okay and then we want to use that emit and we want to emit send and we want to send along with it the message. value and then we’ll just clear the value so message. value set that to an empty string all right now we need to embed the chat uh the the chat input into the chat view so let’s import it so right here we’re going to import chat input and we’re going to come down here and go right above the last div and let’s embed it so chat input and then we want to pass here we want to say at send because remember we from the chat input we emitted a custom event called send so when that’s called basically when we hit the button or we hit enter then that event is going to get called so we need to add a Handler to it and the Handler is simply going to be the chat store. send message whoops chat store. send message and that’s it so now we have our input down at the bottom here so let’s try it out we’ll say who who was the who is the 10th president of the us so AI is thinking and then it comes back 10th president was John Tyler so yeah I mean this is working now one thing that I’d like to add and we’re going to have to do this in the back end is context because you’ll see if I say now uh we’ll say what year what years was he president okay so I’m going to send that a i is thinking to respond to your query I need to know the specific person so it doesn’t have context right it doesn’t know it doesn’t look back and and see that I just asked about John Tyler so we have to add that functionality in the back end I’m actually going to go let’s see so this is the back end here I’m going to open up vs code in the back end okay so this is now my my Express API and we’re going to go to the uh let’s see the server TS and the where we want to do this is going to be the chat endpoint and if you want to break these up into separate files you can I know that this is kind of a long file um but yeah so this is the chat endpoint and let me just figure out where where I want to put this um so we we check for the message the user ID we query users check make sure the user’s there check the user in the database and let’s see then we set our response so let’s go after we check the user in the database and before we send the response so we’re going to go right here and we what we want to do is fetch users past um p pass messages for context and what we want to do here is essentially instead of sending back because right now when we hit slash chat it sends back this it sends the the an object with the role the user rle and then whatever the message is all right uh I’m sorry that’s not what it sends back that’s what we’re sending it and then it sends back down here it sends back the reply but what we want to do is instead of of us sending it only the current message we want to send it we want it to also have context of the last whatever 10 20 messages however however many you want to set it you want to input that into open AI as well as the current message so that way it has context and it can look back and when we say you know what years did he serve then they can look back at the last few messages and respond with that context so to fetch the users um not fetch the users fetch the the users messages we can come down to get messages and right here the chat history we can just copy this this block of code okay and then we’ll put that here so right before we send the the request to open Ai and we’re just selecting from the chats where the user is the user ID I’m going to get rid of this semicolon because I also want to just add order by and we want to order by chats Dot and then create at and then I’m also going to limit it to the last 10 messages if you want to put more that’s fine but just remember the more you put the longer the request is going to take all right so we have that now like I said we need to send not just the current message but but the last the chat history so what I’m going to do is create a variable for actually let’s put a comment here let’s say format the chat history for open AI okay because it has to be formatted in a certain way so I’m going to call this conversation because that’s what it is a bunch of messages in context is a conversation and for the type we’re going to use this uh chat what is it chat completion message param so we want to use that and it’s an array so put some brackets on there and uh I believe we have to bring that in so up at the top oh it was brought in okay so this comes in from open AI resources all right so back to where we were so we’re going to set that and we’re going to use flat map because it needs to be a flattened array so let’s say chat history and then flatmap pass in our function and say for each chat we want to return an array so actually this can be just brackets so we want to return an array that has uh it should look like this right so it should have the role so the user R will have the content of chat. message and the AI role will have the chat reply because we need both we need our messages and the ai’s messages in the conversation in order to have context so now let’s go under that and let’s say uh we’ll put a comment here we’ll say add latest user messages to the conversation okay so we can do that by saying conversation. push and we’re going to push onto it the latest which is this right normally or or what we were doing is just passing this in we still want to pass that in along with this stuff so we’re pushing this onto this so we’ll just put that in there like that all right now we should be able to come down here and instead of for messages instead of doing this we’ll say conversation as and then the chat completion message param array uh let’s see content oh so this right here this this shouldn’t be AI this should be assistant because when you’re dealing with open AI there’s a couple different types that you can use for role there’s user um we’re dealing with assistant here the AI is is the assistant so that should clear up that error all right so now that we’ve done that it should have the context we shouldn’t have to change anything in the front end because it’s still returning the same thing you know that’s still returning the AI response but it should have context now so let’s go ahead and run the back end because I did I stopped it so I’m going to do npm runev all right so now I’m going to come back over here and I’m going to say who was the who was the 11th president of the US okay James K pul now let’s say what years did he serve there we go James K poke served as the president March 4th in 1845 1849 cool so now we have context and I think that’s something that’s you know really important you don’t want to just ask one question and that’s it you want to be able to conversate all right so we’re we’re just about done this one other thing I want to do so let’s say I I was to do like um give me give me a list of the the top five cities in the US when it comes to crime rate and you could take I guess I could interpret that as low lowest crime or best or you know least crime it answers but it’s not formatted very nicely we have number one here Albuquerque number two Baton Rouge so I want this to actually show in a nice list so what we can do is just add a simple format message function in our chat view so let’s go to our chat View and we can use regular Expressions to replace certain um certain tags and so on so let’s uh let’s see where do I want to put this we’ll put it right above the scroll to bottom and let’s say format format AI messages for better display so we’ll call this format message and that’s going to take in text which is going to be a string okay and then we just want to check if there’s no text if there’s no text then we’re just going to return an empty string all right and then we’re going to return a bunch of replace methods with some regular expression and I’m not going to type this out I’m going to paste it in and you guys can get it from the repo if you don’t want to type this stuff in but basically we’re going to preserve line breaks we’re going to bold text um so we’re looking for like new lines and replacing it with a a line break HTML tag bold text inline code um bullet points Etc so the way that we use this is down here where we output the content instead of outputting it in the div inside of these curly braces we’re going to use the the V HTML directive on the div right so this div right here let’s add v- HTML and then we can just set that to the the format message function and then pass in our MSG do content and now as you can see the list is nice and clear all right all right so that’s yeah that’s pretty much it guys um if I were to log out and log in as I think I have some messages with this with uh what was it Brad at Gmail and you can see the code when I asked for a rest API I mean it’s not the best if I make it a little bigger you can see it better it’s not formatted the best but it’s readable you know um but yeah so that’s it we now have a an AI a AI chat bot that works pretty well and will give you you know gp4 powered data now the last thing I’d like to do is actually deploy this and since we have our back end and front end completely separate we’re going to be hosting our back end with render and we’re going to host our front end with versel all right so let’s get into that all right guys so we’re going to go ahead and deploy this project and we have the back end which we’re going to be deploying to render.png all right so I’m going to go to render.jpg sub repos I’m going to choose chat AI API and then there’s just some options that we need to add here so for one um the build Command right so if we look at our package.json we’re using typescript and we need to compile that typescript so we’re going to do that on the server so we need it to run this npm run build in addition to npm install so right here we’re going to say and run npm run build and then the other thing is the the start it’s the server.js is going to be in the disc folder so here instead of node server JS we’re going to say node disc SL server JS all right then we just have some environment variables so in ourv copy everything but the port and then we can say add from. EnV paste that in add those variables and that’s it now we’ll click deploy web service and this can take like a minute or two all right so it says your uh build successful your server is live this is the domain here and we can test this real quick so I can go into Postman and make a new request post request to this that’s not it it didn’t copy there we go all right so we want to do this domain right and then we’re going to do slash and let’s do get Dash messages and then in the body we’re going to add user ID and let’s do johore gmailcom and send and there we go so we’re getting the messages so we know that that the API is now live so now we want to do the front end so I’m going to go to verel and log in with GitHub okay and then we’re going to click add new project we’re going to select chat AI UI this time and let’s see so V build and output settings I believe leave everything we can just leave as is um for environment variables though we want to add the Vore aior key not key what am I doing API underscore URL right because this is going to be our endpoint and we don’t want to use Local Host 8000 or whatever we want to paste in the the render endpoint or the render URL and yeah I think that’s it so let’s click deploy again this can take like a minute or two all right so that took like 10 seconds and then we’re going to continue and let’s check it out if we just click on that and you can see we’re at the live site now and I’m going to log in as let’s say John and John at Gmail start chat and I should see my chats because remember we’re using the same database and let’s try it out I’ll say what is the capital of Texas AI is thinking the capital of Texas is Austin so we have this fully deployed and you can see just how easy that that was all right but that’s it hopefully you guys enjoyed this I may do another video where we create a react front end uh or I might save it for my react course I’m really not sure yet um and I may add on to this we may add actual authentication with you know protect um protection of the actual messages and adding password authentication and so on but I think that this is a really good start and hopefully you guys learned quite a bit from this and thanks for watching if you liked it leave a like and I’ll see you next time
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
The lessons we teach our children in their early years shape the adults they will become. Good manners, personal responsibility, and empathy are not just virtues but essential life skills that pave the way for success and positive social interactions. Parents who instill these habits early on help their children grow into respectful, responsible, and well-adjusted individuals. As Aristotle famously said, “Good habits formed at youth make all the difference.”
Teaching kids foundational rules is not just about discipline—it’s about equipping them with a moral compass that will guide their decisions for life. Children are like sponges, absorbing behaviors, attitudes, and ethics from their surroundings. When parents and caregivers set clear expectations and model good behavior, they create an environment where respect, honesty, and responsibility become second nature. Books like “The Whole-Brain Child” by Daniel J. Siegel highlight how early childhood experiences shape brain development, making these formative years crucial for instilling lasting values.
In this guide, we explore 30 essential rules that every child should learn while they are young. These principles will help them navigate social situations, develop strong character, and foster a sense of responsibility. By integrating these rules into daily routines, parents can nurture independent, compassionate, and well-mannered individuals who contribute positively to society.
1 – Never take what isn’t yours
Teaching children the importance of respecting others’ belongings is one of the first moral lessons they should learn. Understanding the difference between borrowing and stealing lays the foundation for integrity and trustworthiness. When kids learn that taking something without permission is wrong, they begin to develop a sense of honesty and accountability. Encourage them to ask before using anything that doesn’t belong to them and explain why returning borrowed items is just as important. Aesop’s fable “The Boy Who Cried Wolf” illustrates how dishonesty can lead to a loss of trust, reinforcing the lesson that respect for others’ property is crucial.
Parents can reinforce this rule by setting clear boundaries at home. If a child takes a sibling’s toy without asking, use the moment to teach empathy by asking, “How would you feel if someone took your favorite toy without asking?” By helping children see situations from others’ perspectives, they begin to understand why fairness and respect matter in everyday interactions.
2 – Close what you open
Small habits, like closing doors, drawers, and bottles after using them, teach children responsibility and consideration for others. Leaving things open or unfinished can lead to accidents or unnecessary messes. When kids learn to complete small actions, they also develop the discipline needed for bigger responsibilities. As Benjamin Franklin wisely stated, “Small leaks sink great ships.” Teaching attention to detail through simple tasks prepares children for lifelong organization and accountability.
Parents can encourage this habit by making it a part of daily routines. For instance, turning it into a fun game—”Who can close the cupboard the fastest?”—can reinforce the lesson playfully. Consistency is key; gentle reminders and modeling the behavior yourself will ensure children internalize this practice over time.
3 – Put things away when you’re done
A tidy space leads to a tidy mind. Teaching children to clean up after themselves fosters responsibility, discipline, and respect for shared spaces. When kids develop the habit of putting things back where they belong, they also build a sense of order that will serve them well in school, work, and life. Marie Kondo’s book “The Life-Changing Magic of Tidying Up” emphasizes how organization improves mental clarity and reduces stress, making this an essential rule for children to adopt early.
One way to instill this habit is through positive reinforcement. Praising a child when they clean up after playtime encourages them to keep up the good work. Additionally, creating a designated place for toys, books, and clothes makes it easier for children to follow through with the habit.
4 – Say “please” and “thank you”
Politeness is a fundamental social skill that sets the tone for positive interactions. Teaching children to use “please” and “thank you” instills a sense of gratitude and respect. Studies in psychology suggest that gratitude fosters happiness and strengthens relationships. In “Raising Grateful Kids in an Entitled World”, author Kristen Welch emphasizes how simple manners shape a child’s worldview and emotional intelligence.
Parents can reinforce polite language by modeling it themselves. When children see their caregivers expressing appreciation, they naturally adopt similar behaviors. Role-playing exercises, where kids practice polite interactions, also help them internalize this important rule.
5 – Treat others how you want to be treated
The golden rule—treating others with kindness and respect—lays the foundation for strong relationships and emotional intelligence. When children learn to empathize with others, they develop compassion and social awareness. Teaching this principle early helps them understand the impact of their words and actions. As philosopher Confucius said, “Do not do to others what you do not want done to yourself.” This timeless wisdom fosters a culture of kindness and fairness.
Parents can reinforce this lesson through real-life examples and storytelling. Asking questions like, “How would you feel if someone excluded you from a game?” helps children recognize the importance of treating others with dignity. Encouraging small acts of kindness, such as helping a friend or sharing a toy, strengthens their ability to practice empathy in everyday situations.
6 – Finish what you start
Teaching children the value of persistence builds resilience and work ethic. When kids learn to complete tasks—even when they become difficult—they develop self-discipline and a sense of accomplishment. According to Angela Duckworth’s book “Grit: The Power of Passion and Perseverance”, the ability to push through challenges is a key predictor of success.
Parents can encourage perseverance by celebrating small victories. Whether it’s finishing a puzzle or completing homework, recognizing their efforts reinforces the habit of following through. If a child wants to quit an activity, guide them to reflect on their progress and encourage them to set realistic goals. Teaching children to persist, even in the face of challenges, prepares them for adulthood.
7 – Listen when others are speaking
Active listening is a crucial social skill that fosters respect and understanding. When children learn to truly listen instead of just waiting for their turn to talk, they develop stronger relationships and become better communicators. Research in “How to Win Friends and Influence People” by Dale Carnegie highlights how listening attentively makes others feel valued and respected.
One way to cultivate this habit is through modeling. When children speak, give them your full attention, making eye contact and nodding to show you’re engaged. Encourage them to do the same when others are talking. Simple exercises, such as repeating back what someone said before responding, can reinforce the importance of listening actively.
8 – Apologize when you’re wrong
Owning up to mistakes is a sign of maturity and integrity. Teaching children to apologize sincerely helps them develop accountability and fosters trust in relationships. According to psychologist Brené Brown in “The Gifts of Imperfection”, vulnerability—including admitting faults—strengthens emotional connections and self-awareness.
Parents can help children understand that apologies are not just about saying “sorry” but about making things right. Encourage them to express what they did wrong and how they plan to fix it. For example, instead of a simple “I’m sorry,” guide them to say, “I’m sorry for taking your toy without asking. I’ll ask next time.” This approach teaches genuine accountability.
9 – Share with others
Sharing teaches generosity, cooperation, and social harmony. Children who learn to share develop better friendships and emotional intelligence. Studies in child psychology show that early lessons in sharing lead to better conflict resolution skills later in life. In “Mind in the Making”, Ellen Galinsky discusses how sharing fosters cognitive and social growth.
To encourage sharing, parents can create positive reinforcement systems. Praising a child when they willingly share reinforces the behavior. Using storytelling—such as reading books like “The Rainbow Fish”, which highlights the joy of sharing—can also help instill this habit.
10 – Respect other people’s space and belongings
Teaching children to respect personal boundaries is essential for developing healthy relationships. This includes understanding that others may not want to be touched, that their belongings should be left untouched, and that personal space matters. Psychologist Dr. Henry Cloud, in “Boundaries with Kids”, emphasizes how teaching respect for personal space helps children develop emotional intelligence and self-control.
One practical way to teach this is through role-playing scenarios. For example, parents can ask, “How would you feel if someone barged into your room without knocking?” By discussing personal experiences, children gain a clearer understanding of why respecting others’ space and belongings is important.
11 – Say “excuse me” when interrupting
Politeness and patience go hand in hand. Teaching children to say “excuse me” before interrupting instills respect and consideration for others. This small phrase helps them understand the importance of waiting their turn to speak, reinforcing social etiquette. As Emily Post, a pioneer in etiquette, once said, “Manners are a sensitive awareness of the feelings of others.”
Parents can practice this rule through gentle reminders. If a child interrupts, calmly pause and say, “Let’s wait until I’m finished talking. Then you can have your turn.” Over time, children will naturally adopt this habit, leading to more respectful communication.
12 – Be honest
Honesty is the foundation of trust. When children learn the value of truthfulness, they develop integrity and strong moral character. Research in “The (Honest) Truth About Dishonesty” by Dan Ariely reveals that small lies can snowball into bigger deceptions, highlighting the importance of honesty from a young age.
Encouraging honesty requires creating a safe space for children to tell the truth without fear of harsh punishment. Parents should praise honesty, even when the truth is difficult. Instead of reacting with anger, use mistakes as learning opportunities by discussing how honesty builds trust and strengthens relationships.
13 – Take care of your own things
Responsibility starts with taking care of one’s belongings. Teaching children to be mindful of their possessions helps them develop a sense of ownership and accountability. When they learn to keep their toys, clothes, and school supplies in order, they cultivate habits that will serve them well into adulthood. As psychologist Dr. John Rosemond emphasizes in “Parenting by The Book”, giving children responsibility for their belongings fosters independence and self-discipline.
Parents can encourage this habit by making organization a daily routine. Assigning children small tasks, such as making their bed or putting away their toys, helps them develop a structured mindset. Reinforcing the idea that taking care of their belongings means they last longer also instills a sense of value and appreciation.
14 – Wait your turn
Patience is a virtue, and waiting one’s turn is a key social skill. Whether in conversations, games, or waiting in line, learning to wait teaches children respect, self-control, and consideration for others. Studies in child development suggest that delayed gratification is a strong predictor of future success. In “The Marshmallow Test”, psychologist Walter Mischel explains how children who learn to wait for rewards tend to perform better academically and socially.
Parents can help children develop patience through everyday activities. Playing board games, where each participant must wait their turn, is a practical way to reinforce this rule. Another method is using a timer to help children visualize waiting periods, making patience more tangible and manageable.
15 – Do your best in everything you do
Excellence is a habit, not a one-time effort. Teaching children to put forth their best effort in school, hobbies, and daily tasks fosters perseverance and a strong work ethic. In “Mindset”, Carol S. Dweck explains how a growth mindset—believing that effort leads to improvement—helps children develop resilience and ambition.
Parents should emphasize the value of effort over perfection. Encouraging children to take pride in their work, whether it’s a school project or a chore, builds confidence. Praise should focus on hard work rather than just the outcome, reinforcing the idea that persistence is more important than immediate success.
16 – Wash your hands before eating
Basic hygiene is a crucial lesson in self-care. Teaching children to wash their hands before meals helps prevent illness and instills lifelong healthy habits. Studies by the Centers for Disease Control and Prevention (CDC) highlight how proper handwashing reduces the spread of germs and infections.
One effective way to reinforce this habit is by making it routine—washing hands before every meal, after using the restroom, and after playing outside. Parents can also use fun songs or timers to make handwashing enjoyable for younger children, ensuring the habit sticks.
17 – Leave places better than you found them
A sense of responsibility extends beyond personal spaces. Teaching children to clean up after themselves, whether at home, school, or public places, fosters respect for the environment and community. Environmentalists like Rachel Carson, in “Silent Spring”, stress the importance of small actions in creating a cleaner world.
Parents can model this behavior by demonstrating simple habits, like picking up trash at the park or wiping down a table after use. Encouraging children to take pride in leaving spaces neat reinforces the idea that everyone has a role in maintaining a respectful and clean environment.
18 – Be on time
Punctuality is a sign of respect for others’ time and a key trait of responsible individuals. When children learn to be on time, they develop discipline, reliability, and time management skills. In “Atomic Habits”, James Clear emphasizes that small habits, like showing up on time, build a foundation for success.
Parents can instill punctuality by setting structured routines, such as leaving for school at a specific time every morning. Teaching children to plan ahead—laying out clothes the night before or setting alarms—helps them take responsibility for their schedules.
19 – Help others when you can
Acts of kindness enrich both the giver and the receiver. Teaching children to help others, whether through small gestures or bigger acts of service, fosters empathy and social responsibility. Studies in “The How of Happiness” by Sonja Lyubomirsky show that helping others contributes to personal happiness and fulfillment.
Parents can encourage helpfulness by creating opportunities for children to assist at home, such as setting the table or helping a sibling. Volunteering as a family at community events also reinforces the value of giving back and making a positive impact.
20 – Keep your promises
Trust is built on keeping one’s word. When children learn that promises are meant to be kept, they develop integrity and reliability. In “The Seven Habits of Highly Effective People”, Stephen Covey explains that following through on commitments builds credibility and self-respect.
Parents can demonstrate this lesson by honoring their own promises, whether it’s a planned family outing or a bedtime story. Teaching children that broken promises lead to disappointment helps them understand the importance of being dependable.
21 – Eat your vegetables
Good nutrition starts early. Encouraging children to eat their vegetables helps develop lifelong healthy eating habits. Research in “The Omnivore’s Dilemma” by Michael Pollan highlights the long-term health benefits of a balanced diet, emphasizing whole, unprocessed foods.
Parents can make vegetables more appealing by involving children in meal preparation or presenting them in fun ways, such as colorful plates or creative shapes. Positive reinforcement—like praising them for trying new vegetables—also encourages healthier eating habits.
22 – Ask before borrowing
Respecting others’ belongings includes asking for permission before using something that isn’t yours. This simple rule teaches children the importance of consent and boundaries. In “Boundaries: When to Say Yes, How to Say No” by Dr. Henry Cloud, the concept of personal ownership is emphasized as a fundamental social skill.
Parents can reinforce this rule by setting a household standard—if a child wants to borrow a sibling’s toy, they must ask first. Practicing polite requests, such as “May I use this?” helps children internalize this respectful habit.
23 – Respect animals and nature
Teaching children to respect animals and the environment instills compassion and responsibility. Studies show that children who grow up caring for pets or spending time in nature develop stronger empathy and environmental awareness. Jane Goodall, in “Reason for Hope”, discusses how fostering a love for animals helps create a more compassionate society.
Parents can encourage this respect by involving children in pet care or outdoor activities. Teaching them to pick up litter, avoid disturbing wildlife, and treat animals gently reinforces the value of respecting all living things.
24 – Use your indoor voice inside
Learning when and where to use different tones of voice teaches children social awareness. Speaking softly indoors shows consideration for others and helps maintain a peaceful environment. In “NurtureShock”, Po Bronson highlights how teaching self-regulation from an early age improves emotional intelligence.
One way to reinforce this habit is through gentle reminders. Parents can establish “quiet time” routines where children practice speaking softly, helping them develop volume control in different situations.
25 – Look people in the eye when speaking
Eye contact is a key aspect of confident communication. Teaching children to look at others when speaking helps build self-assurance and respect. Research in “The Charisma Myth” by Olivia Fox Cabane shows that eye contact enhances credibility and social connection.
Parents can practice this by engaging in face-to-face conversations with their children. Role-playing exercises, where they practice maintaining eye contact during greetings or discussions, can make this habit second nature.
26 – Don’t talk with your mouth full
Table manners reflect respect for others and personal etiquette. Teaching children not to talk with their mouths full helps them develop good dining habits that will serve them in social and professional settings. According to etiquette expert Emily Post, proper table manners create a positive impression and show consideration for those around us.
Parents can reinforce this rule by modeling good behavior during family meals. If a child forgets, gently remind them to finish chewing before speaking. Fun activities, like role-playing a fancy dinner, can make learning etiquette enjoyable while reinforcing the importance of mindful eating.
27 – Help clean up, even if it’s not your mess
Responsibility extends beyond personal belongings. Teaching children to help clean up, even if they didn’t create the mess, fosters teamwork and accountability. Research in “The Montessori Method” by Maria Montessori emphasizes that children develop a sense of community and responsibility when they participate in shared tasks.
Parents can encourage this habit by making cleaning a group effort. Instead of saying, “Pick up your mess,” try, “Let’s clean this up together.” Praising children when they take the initiative to tidy up reinforces their willingness to contribute.
28 – Speak kindly to others
Words have power. Teaching children to choose kind words helps build strong relationships and emotional intelligence. Dr. Marshall Rosenberg, in “Nonviolent Communication”, explains how mindful speech fosters empathy and prevents conflicts.
Parents can set an example by speaking kindly themselves. Encouraging children to use phrases like “That was a great job!” or “I appreciate you” helps them recognize the impact of positive words. If unkind words are used, discussing how they make others feel reinforces the importance of speaking with kindness.
29 – Be a good sport
Winning and losing with grace is an essential life skill. Teaching children sportsmanship—whether in games, school, or social situations—helps them handle challenges and setbacks with resilience. In “Raising Resilient Children”, Dr. Robert Brooks emphasizes that learning to lose gracefully builds emotional strength and character.
Parents can reinforce this by praising effort over outcome. Instead of focusing on winning, encourage children to reflect on what they learned from the experience. Modeling good sportsmanship—such as shaking hands after a game—helps them adopt this behavior naturally.
30 – Take care of your own health
Good health is a lifelong priority. Teaching children to maintain their physical and mental well-being fosters long-term self-care habits. Dr. Benjamin Spock, in “Baby and Child Care”, highlights that children who learn self-care early are more likely to make healthy choices as adults.
Parents can support this by creating routines around healthy habits—regular exercise, balanced meals, and sufficient sleep. Encouraging children to listen to their bodies, such as drinking water when thirsty or resting when tired, helps them develop an awareness of their own well-being.
Conclusion
Teaching children these fundamental rules while they are young sets them up for success in adulthood. These lessons go beyond simple instructions—they shape character, foster social skills, and build a foundation of responsibility, empathy, and integrity. As Aristotle once said, “Good habits formed at youth make all the difference.” By reinforcing these principles through daily practice and parental modeling, children grow into thoughtful, respectful, and well-rounded individuals.
Raising children with these values is a long-term investment, but the rewards are invaluable. They will not only navigate the world with confidence but also contribute positively to their communities. Ultimately, these small lessons create a ripple effect, shaping not just one child but an entire generation of responsible and kind individuals.
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
Losing weight doesn’t mean giving up on snacking—it just means making smarter choices. The right snacks can curb hunger, boost metabolism, and keep your energy levels steady throughout the day. With 2025 ushering in new trends in health and nutrition, it’s more important than ever to choose snacks that align with your weight loss goals while providing essential nutrients.
Many people struggle with weight loss because they focus only on cutting calories rather than choosing nutrient-dense foods. Research suggests that high-protein, fiber-rich, and healthy fat-containing snacks can help you feel full longer, reducing overall calorie intake. According to Dr. Michael Greger, author of How Not to Diet, “It’s not about eating less; it’s about eating right.” By incorporating the healthiest snacks into your diet, you can maintain steady weight loss without feeling deprived.
This guide will explore the best snacks to eat if you’re trying to lose weight in 2025, from protein-packed nuts and seeds to fiber-rich fruits and vegetables. Whether you’re looking for a quick bite between meals or a satisfying post-workout snack, these options will help you stay on track. Let’s dive into the best snacks to keep you full, fueled, and focused on your weight loss journey.
1 – Try Adding These Healthiest Snacks for Weight Loss into Your Daily Food Plan
Snacking strategically can be a game-changer when it comes to losing weight. Rather than reaching for highly processed, calorie-dense foods, selecting nutrient-rich snacks can support satiety and prevent overeating at meal times. Studies show that snacks high in fiber, protein, and healthy fats contribute to better appetite control and metabolic balance. Experts recommend choosing whole, minimally processed snacks that align with your nutritional needs and energy levels.
Including weight-loss-friendly snacks in your daily routine doesn’t have to be complicated. Planning ahead and keeping healthy options on hand can prevent impulse choices that derail progress. A well-balanced snack can keep blood sugar levels stable, preventing energy crashes and excessive hunger. By incorporating these smart snacking habits, you can make weight loss more sustainable without feeling restricted or deprived.
2 – Best Snacks for Weight Loss
The best snacks for weight loss are those that keep you full while providing essential nutrients. Protein-rich snacks help maintain muscle mass, while fiber-packed options aid digestion and satiety. Healthy fats, such as those found in nuts and seeds, also play a key role in keeping cravings at bay.
Choosing the right snacks means focusing on whole foods rather than processed alternatives. Instead of sugary granola bars or empty-calorie crackers, opt for nutrient-dense choices like Greek yogurt, fresh fruit, or air-popped popcorn. By making mindful decisions about what you eat between meals, you can enhance your weight loss efforts while still enjoying delicious and satisfying snacks.
3 – Nuts and Seeds
Nuts and seeds are powerhouse snacks packed with protein, fiber, and healthy fats. Studies have shown that consuming nuts in moderation can support weight loss by reducing hunger and preventing overeating. Their nutrient density makes them an excellent choice for keeping energy levels steady and cravings under control.
Almonds, walnuts, and pumpkin seeds, for example, are rich in omega-3 fatty acids and antioxidants, which benefit both brain health and metabolism. While nuts are calorie-dense, their combination of protein and fiber ensures that a small portion is satisfying. To maximize their benefits, choose raw or dry-roasted varieties without added salt or sugar.
4 – Avocado
Avocados are often called a “superfood” for a good reason. They are loaded with heart-healthy monounsaturated fats, which have been linked to weight loss and improved metabolic health. According to Dr. Joel Fuhrman, author of Eat to Live, “Healthy fats from whole plant sources support weight loss by promoting satiety and reducing cravings for unhealthy foods.”
A simple way to enjoy avocados as a snack is by spreading them on whole-grain toast, adding them to smoothies, or making guacamole with fresh vegetables. Despite their higher calorie content, avocados can help regulate appetite and prevent overeating when consumed in moderation.
5 – Yogurt
Greek yogurt is a protein-packed snack that supports weight loss by keeping you full longer. Its high protein content helps preserve muscle mass while reducing hunger hormones, making it an excellent choice for those trying to shed pounds. Additionally, probiotic-rich yogurt improves gut health, which plays a role in metabolism and digestion.
To get the most benefits, choose plain, unsweetened Greek yogurt and add natural sweeteners like fresh fruit or a drizzle of honey. Many store-bought yogurts contain hidden sugars that can counteract their health benefits. For an extra nutrient boost, top your yogurt with chia seeds or nuts.
6 – Popcorn
Popcorn is a surprisingly effective weight-loss snack—if prepared correctly. Unlike butter-laden movie theater popcorn, air-popped popcorn is low in calories and high in fiber. A single serving can help you feel full without excess fat or artificial additives. Studies indicate that fiber-rich snacks like popcorn help regulate appetite and prevent overeating.
To keep it healthy, opt for air-popped popcorn and avoid excessive butter or flavored toppings. A sprinkle of nutritional yeast can add a cheesy flavor without extra calories, while a dash of cinnamon or paprika can enhance taste without compromising health benefits.
7 – Chickpeas
Chickpeas are an excellent source of plant-based protein and fiber, making them a great snack for weight loss. A study published in Obesity found that people who consumed legumes regularly had better weight management and lower body fat levels. Roasted chickpeas provide a crunchy, satisfying texture, making them an ideal alternative to processed chips.
You can roast chickpeas at home with olive oil and spices or blend them into hummus for a protein-rich dip. Their slow-digesting carbohydrates prevent energy crashes, keeping you full for longer. Whether eaten on their own or paired with fresh vegetables, chickpeas are a nutrient-dense snack that supports weight management.
8 – Hard-Boiled Eggs
Hard-boiled eggs are a convenient, protein-rich snack that can support weight loss efforts. Eggs contain high-quality protein and essential amino acids, which help maintain muscle mass while promoting satiety. Research in the Journal of the American College of Nutrition suggests that consuming eggs for breakfast can reduce overall calorie intake throughout the day.
Pairing hard-boiled eggs with a side of vegetables or whole-grain crackers enhances their nutritional value. Adding a sprinkle of black pepper or chili flakes can boost metabolism, making this simple snack even more beneficial for weight loss.
9 – Edamame
Edamame, or young soybeans, are a protein-packed snack ideal for weight management. These green pods are rich in plant-based protein and fiber, which help regulate hunger and stabilize blood sugar levels. Studies have shown that soy protein can aid in fat loss while preserving lean muscle mass.
A small bowl of steamed edamame with a pinch of sea salt makes for a satisfying snack. They can also be tossed into salads or blended into dips. Their balance of protein and fiber makes them a perfect addition to any weight-loss meal plan.
10 – Oatmeal
Oatmeal is often associated with breakfast, but it also works as a filling snack. Its high fiber content, particularly beta-glucan, promotes feelings of fullness and stabilizes blood sugar levels. A study published in The Journal of Nutrition found that whole grains like oats can support healthy weight loss by improving digestion and reducing hunger.
For a weight-loss-friendly snack, choose unsweetened oatmeal and add natural toppings like cinnamon, fresh fruit, or nuts. Instant flavored oatmeal packets often contain added sugars, which can counteract its benefits. Overnight oats with chia seeds and almond butter provide a nutrient-dense, satisfying option.
11 – Dried Fruit
Dried fruit can be a great snack when consumed in moderation. Unlike processed sweets, dried fruits contain natural sugars along with fiber, vitamins, and antioxidants. However, portion control is key, as dried fruit is calorie-dense.
Opt for unsweetened varieties of dried fruit and pair them with nuts for a balanced snack. Dates, figs, and dried apricots provide a natural energy boost while supporting digestion. Reading ingredient labels is crucial to avoid added sugars or preservatives.
12 – Kale Chips
Kale chips are a nutrient-rich alternative to traditional potato chips. Kale is packed with fiber, vitamins A and C, and antioxidants that support weight loss and overall health. Unlike fried snacks, baked kale chips provide crunch without excess oil or empty calories.
You can make kale chips at home by tossing fresh kale leaves with olive oil and seasoning before baking them at a low temperature. Adding a sprinkle of nutritional yeast enhances their flavor while providing extra protein and B vitamins.
13 – Almonds
Almonds are a classic weight-loss snack due to their healthy fat content, protein, and fiber. Research published in The International Journal of Obesity suggests that incorporating almonds into a calorie-controlled diet can enhance weight loss and metabolic health.
For the best results, opt for raw or dry-roasted almonds instead of salted or sugar-coated varieties. A small handful can help curb hunger and provide long-lasting energy without causing spikes in blood sugar.
14 – Walnuts
Walnuts are an excellent source of omega-3 fatty acids, which support brain function and heart health. Their combination of protein and healthy fats makes them a filling snack for weight loss. Studies have shown that regular walnut consumption can help regulate appetite by activating areas of the brain linked to hunger control.
Eating walnuts in moderation can help prevent overeating. Pair them with dried fruit or sprinkle them on Greek yogurt for a nutrient-dense snack.
15 – Cashews
Cashews are creamy, nutrient-rich nuts that provide healthy fats, magnesium, and protein. They are lower in fiber than some other nuts but still contribute to feelings of satiety.
Enjoying cashews in small portions can help satisfy cravings without leading to excessive calorie intake. They work well in homemade trail mixes or as a topping for salads and smoothie bowls.
16 – Pistachios
Pistachios are one of the best nuts for weight loss due to their lower calorie content and high protein and fiber levels. A study in Nutrients found that eating pistachios can lead to improved weight management and reduced body fat.
One unique advantage of pistachios is that they require shelling, which slows down consumption and promotes mindful eating. Choosing unsalted, in-shell pistachios can help prevent overeating.
17 – Macadamia Nuts
Macadamia nuts are rich in monounsaturated fats, which have been linked to improved metabolism and heart health. Although they are calorie-dense, their healthy fat profile makes them a satisfying snack when eaten in moderation.
Pair macadamia nuts with dark chocolate or coconut flakes for a balanced and indulgent yet weight-loss-friendly treat.
18 – Chia Seeds
Chia seeds are a nutritional powerhouse that supports weight loss due to their high fiber and omega-3 content. When soaked in liquid, they expand, creating a gel-like consistency that helps with satiety and digestion. A study in Nutrition Research and Practice found that consuming chia seeds can promote fullness and reduce overall calorie intake.
Adding chia seeds to yogurt, smoothies, or oatmeal can enhance their nutritional profile. You can also make a chia pudding by mixing them with almond milk and letting them soak overnight. This versatile seed provides long-lasting energy and aids in stabilizing blood sugar levels.
19 – Flaxseeds
Flaxseeds are packed with fiber, protein, and healthy fats, making them an excellent addition to any weight-loss plan. Research published in Obesity Reviews suggests that flaxseeds can help reduce appetite and improve metabolic health. Their lignan content also supports hormone balance and digestion.
To get the most benefits, grind flaxseeds before consuming them, as whole flaxseeds may pass through the digestive tract undigested. Sprinkle them over salads, blend them into smoothies, or mix them into oatmeal for an easy nutrition boost.
20 – Hemp Seeds
Hemp seeds are a complete source of plant-based protein, containing all nine essential amino acids. They are also rich in omega-3 fatty acids and fiber, which support satiety and metabolic health. Studies suggest that consuming hemp seeds can help regulate appetite and reduce unhealthy cravings.
You can easily incorporate hemp seeds into your diet by sprinkling them over yogurt, salads, or oatmeal. Their mild, nutty flavor makes them a versatile addition to many dishes.
21 – Pumpkin Seeds
Pumpkin seeds are a nutrient-dense snack that provides protein, fiber, and essential minerals like magnesium and zinc. Their combination of protein and healthy fats makes them particularly effective for keeping hunger at bay. A study in Appetite found that including pumpkin seeds in the diet can support weight management and prevent overeating.
Raw or roasted pumpkin seeds make a convenient snack, or they can be added to trail mixes and granola. Avoid varieties with excessive salt or added flavors to keep them as healthy as possible.
22 – Sunflower Seeds
Sunflower seeds are a great source of vitamin E, healthy fats, and protein. Their high fiber content helps promote satiety and digestive health, making them a smart choice for weight loss.
To maximize their benefits, opt for unsalted sunflower seeds and enjoy them in moderation. They can be eaten on their own or sprinkled over salads and yogurt for extra crunch.
23 – Raisins
Raisins offer a natural source of energy while providing fiber, antioxidants, and iron. While they contain natural sugars, they can be a healthy snack when consumed in small portions. Pairing raisins with nuts helps balance their sugar content with protein and healthy fats.
Look for unsweetened raisins with no added oils or preservatives. Adding them to oatmeal or homemade trail mix can provide a quick energy boost without causing blood sugar spikes.
24 – Dried Cranberries
Dried cranberries are packed with antioxidants and fiber, but they are often sold with added sugar. Choosing unsweetened varieties ensures you get the benefits without excess calories.
Cranberries pair well with nuts, seeds, or yogurt, making them a versatile addition to weight-loss-friendly snacks. Their tart flavor can satisfy cravings for something sweet without resorting to processed sugar.
25 – Dried Apricots
Dried apricots are high in fiber and essential vitamins like vitamin A and potassium, which support digestion and hydration. Their natural sweetness makes them a great alternative to processed candies or desserts.
Eating dried apricots in moderation can help control sugar cravings while providing beneficial nutrients. Pairing them with almonds or walnuts adds protein and healthy fats, making for a balanced snack.
26 – Dried Pears
Dried pears are another fiber-rich snack that supports digestion and satiety. They provide a natural sweetness while offering a good amount of antioxidants and vitamins.
To keep your snack as healthy as possible, choose unsweetened dried pears with no added preservatives. Enjoy them with nuts or yogurt for a more balanced nutritional profile.
27 – Dried Strawberries
Dried strawberries are a nutrient-dense snack full of vitamin C and fiber. Unlike fresh strawberries, their dried form is more concentrated in natural sugars, so portion control is key.
Adding dried strawberries to oatmeal, yogurt, or homemade granola can enhance their nutritional benefits. Opt for freeze-dried versions without added sugar for the healthiest choice.
28 – Banana Chips
Banana chips can be a crunchy, satisfying snack, but many store-bought versions are fried and coated in sugar. Choosing baked or dehydrated banana chips without added sweeteners is a better option.
Pairing banana chips with nuts or dark chocolate can help balance their natural sugars with protein and healthy fats. Eating them in moderation ensures they remain a weight-loss-friendly choice.
29 – Don’t Replace Meals with Snacks
While healthy snacks can support weight loss, they should never replace well-balanced meals. Skipping meals in favor of snacking can lead to nutrient deficiencies and unstable energy levels. Experts emphasize the importance of structured eating patterns to maintain a healthy metabolism.
Instead of relying on snacks as meal substitutes, use them to complement your daily food intake. A well-balanced diet includes proper meals with protein, healthy fats, and complex carbohydrates, alongside mindful snacking.
30 – Enjoy Your Food
Losing weight doesn’t mean depriving yourself of enjoyable food. Eating should be a pleasurable experience, and choosing delicious, nutrient-dense snacks can make the process more sustainable. Mindful eating practices, such as savoring each bite and focusing on flavors, can help prevent overeating.
According to The Joy of Eating by Jane Hirschmann, cultivating a positive relationship with food is key to long-term health. By appreciating the taste and texture of healthy snacks, you can stay committed to your weight loss goals without feeling restricted.
31 – Exercise Regularly
Snacking alone won’t lead to significant weight loss without physical activity. Exercise plays a crucial role in burning calories, building muscle, and improving overall metabolism. According to Dr. Mark Hyman, author of Food: What the Heck Should I Eat?, “Movement is medicine for weight management and long-term health.”
Pairing nutritious snacks with an active lifestyle ensures better results. Whether it’s strength training, cardio, or yoga, regular movement helps maintain a balanced approach to weight loss.
32 – Eat More Plants
A plant-based diet is linked to sustainable weight loss and overall well-being. Fruits, vegetables, nuts, seeds, and whole grains provide essential nutrients while being naturally lower in calories. A study in The American Journal of Clinical Nutrition found that plant-based eaters tend to have healthier body weights and better metabolic health.
Incorporating more plant-based snacks, such as hummus with veggies or fruit with almond butter, supports both weight loss and long-term health. Prioritizing whole, unprocessed foods ensures you get the most nutrients per calorie.
33 – Be Patient
Weight loss is a journey, not an overnight transformation. It takes time for the body to adjust to new eating habits and for results to become visible. Patience and consistency are key to sustainable success.
Dr. Jason Fung, author of The Obesity Code, emphasizes that “long-term weight management is about making gradual lifestyle changes rather than relying on quick fixes.” By focusing on nourishing snacks and balanced meals, you can achieve lasting results without frustration.
Conclusion
Choosing the right snacks is a powerful tool in your weight-loss journey. By opting for nutrient-dense, high-protein, and fiber-rich options, you can keep hunger at bay, stabilize blood sugar, and support metabolism. Whether it’s nuts and seeds, yogurt, or dried fruit, the key is balance and moderation.
Beyond snacking, adopting a holistic approach that includes mindful eating, regular exercise, and patience will yield the best results. As nutrition experts emphasize, sustainable weight loss comes from long-term habits, not temporary restrictions. With these smart snacking strategies, you can achieve your health goals while still enjoying delicious food.
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
Glenn Beck’s019-It IS About Islam examines the historical and contemporary relationship between Islam and the West, challenging common narratives. The book argues that many widely held beliefs about Islam, such as its inherent peacefulness and the moderation of certain groups, are inaccurate. Beck explores the historical development of Islam, focusing on the life of Muhammad and the emergence of various interpretations and sects. He also analyzes the rise of extremist groups like ISIS and al-Qaeda, connecting their ideologies to historical precedents. Finally, the book critiques the West’s response to these groups and the role of political and media narratives in shaping public understanding.
Understanding Islam: Core Tenets, History, and Controversies
Here is a study guide based on the provided source material, designed to enhance your understanding of key concepts:
I. Core Islamic Concepts
Quran: Muslims believe the Quran to be the direct word of Allah, as revealed to Muhammad [1]. It is not considered a collection of stories written by humans, but rather, the first-person voice of God [1]. Unlike the Bible, it is believed to be unchangeable [1].
Hadith: These are oral traditions recounting the life and practices of Muhammad [2, 3]. Because the Quran can be contradictory and confusing, the Hadith became very important in determining the rules for daily life [2]. There are many “weak” or fraudulent Hadith, and the most authoritative collectors were not born until nearly 180 years after Muhammad’s death [4].
Sharia Law: Sharia law is a wide-ranging system that encompasses crime, politics, economics, and personal matters [5]. It is not a single document, leading to different interpretations [5]. Sharia is derived from the Quran, the Hadith, Ijma (consensus of Muslim scholars), and Qiyas (reasoning by analogy) [3]. Many Muslims believe that Sharia is the only acceptable law for Muslims [3, 6].
Some Muslims seek to follow Sharia even in Western countries, attempting to solve disputes within its limits [7]. Some believe a Muslim judge should rule by Sharia law, and hate man-made law [7].
Jihad: Jihad is often translated as “struggle,” but it has multiple interpretations [8, 9]. Some Muslims and Islamic scholars define it as an inner struggle to do good [8, 9]. However, it is also considered a holy war, an obligation from Allah [10]. Some interpret it as a means to purify oneself or one’s community [8]. Some believe that jihad is a path to establish Islam over all other religions [11].
Caliphate: A caliphate is an Islamic empire ruled by a successor to the prophet Muhammad [12]. The first caliph was Abu Bakr, Muhammad’s father-in-law [12].
II. Historical Context
Jefferson’s Quran: Thomas Jefferson owned one of the first English translations of the Quran, which he acquired in 1765 [13, 14]. He was curious about laws of many kinds, including those that claimed to carry the word of God [14].
Early Islamic Expansion: After Muhammad’s death, the Muslim community faced challenges in uniting around a common direction, due to the lack of a complete written Quran [2]. This led to reliance on memories, written fragments of God’s word, and the Hadith [2].
Sunni-Shia Split: The loss of Muhammad’s divine revelations and leadership led to divisions within Islam, particularly the split between Sunnis and Shias [2].
Wahhabism and Salafism: These movements sought to return to what they considered to be the original, pure form of Islam [15]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts and practices [15].
The Muslim Brotherhood: Founded in the 1930s, the Muslim Brotherhood views jihad as an obligation and seeks to model themselves on the martyrs [10]. Documents have revealed their plan to transform America into an Islamist society [11]. They aim to destroy Western civilization and make God’s religion victorious [11].
III. Key Figures
Muhammad: Considered by Muslims to be the last prophet, his life and teachings form the basis of Islam [1]. The Quran is believed to be the direct word of God as revealed to him [1].
Abu Bakr: The first caliph, or successor, to Muhammad, appointed after Muhammad’s death [12].
Hassan al-Banna: Founder of the Muslim Brotherhood [10].
Sayyid Qutb: An influential figure whose writings are embraced by jihadist groups [16].
Osama bin Laden: A key figure in al-Qaeda, his organization sought to destroy the United States [8].
Abu Bakr Naji: An al-Qaeda theologian who wrote “The Management of Savagery”, which is considered a key strategic text for jihadist groups [17, 18].
IV. Controversial Issues and Criticisms
Violence and Jihad: Some argue that the concept of jihad is often used to justify violence and terrorism [8, 10]. Some interpret jihad as a fight against non-believers [19]. There is debate over whether the term jihad refers to an inner struggle for good, or an external physical struggle [8, 9].
Sharia Law in the West: Some fear the implementation of Sharia law in Western countries, noting the existence of Sharia courts and the potential conflict with secular legal systems [20].
Treatment of Non-Muslims: Historically, non-Muslims in Muslim-controlled lands have sometimes been given a second-class status (dhimmi), required to pay a tribute (jizya) [21, 22]. There are documented instances of massacres and enslavement of non-Muslims by Muslim forces [22].
Freedom of Speech: Some Islamic texts, like Ash-Shifa, advocate violence against those who disrespect Muhammad [23, 24]. This creates tension with Western values regarding freedom of expression [23].
Apologists: Some scholars and academics are accused of downplaying or ignoring the violent aspects of Islam by focusing on more peaceful interpretations [9, 25].
The Role of Western Foreign Policy: Some sources claim that the West is attempting to blame itself for terrorism, rather than acknowledging that the actions of terrorist groups are solely their own [26].
V. Key Lies
The source material includes a section called “Thirteen Deadly Lies,” which addresses common misconceptions about Islam [13]. It states that claims such as “The Muslim Brotherhood is a moderate, mainstream Islamic group” [13] and “Islam respects freedom of speech” [13] are lies. Other lies include: Muslims don’t seek to live under Sharia [5], and Islam translates to peace [27].
VI. Strategies for Understanding
Go to Primary Sources: It is essential to go to the primary Islamic sources, such as the Quran and Hadith, to understand the religion [28, 29].
Understand Motivations: To understand enemies, one must understand their motivations and goals [30].
Challenge Misconceptions: It is important to challenge misconceptions and stereotypes about Islam [31].
VII. The Need for Action
Educated Citizenry: An educated citizenry needs to fight back against what the source material considers lies about Islam [30].
Truth: The source material suggests that the truth needs to be known by the public, despite what is claimed by politicians and the mainstream media [31].
This study guide should help you navigate the complex information presented in the sources. Remember to consult the source material directly for a more detailed understanding of each point.
Islam, Islamist Extremism, and the West
Here is a briefing document based on the provided source material and our conversation history:
Subject: Understanding Key Aspects of Islam and Islamist Extremism
I. Core Islamic Texts and Concepts
Quran: Considered by Muslims to be the direct word of Allah, as revealed to Muhammad [1, 2]. It is not considered a collection of stories written by humans [2].
It is believed to be unchangeable, unlike the Bible [1].
Hadith: Oral traditions recounting the life and practices of Muhammad. These became important for determining rules for daily life [2].
Many Hadith are considered “weak” or fraudulent [2]. The most authoritative collectors were not born until nearly 180 years after Muhammad’s death [3].
Sharia Law: A comprehensive system encompassing crime, politics, economics, and personal matters, derived from the Quran, Hadith, Ijma (consensus), and Qiyas (reasoning by analogy) [4].
Many Muslims believe Sharia is the only acceptable law for Muslims [4]. Some seek to follow Sharia even in Western countries [4].
Jihad: Often translated as “struggle,” with multiple interpretations [5, 6].
Some define it as an inner struggle to do good [5].
Others consider it a holy war, an obligation from Allah to purify oneself or one’s community, and a path to establish Islam over all other religions [5, 7].
Caliphate: An Islamic empire ruled by a successor to the prophet Muhammad [8].
The first caliph was Abu Bakr, Muhammad’s father-in-law [8].
II. Key Historical Developments
Early Islamic Expansion: After Muhammad’s death, the Muslim community lacked a complete written Quran, leading to reliance on memories, fragments, and Hadith [2].
Sunni-Shia Split: Divisions arose within Islam due to the loss of Muhammad’s divine revelations and leadership, most notably the split between Sunnis and Shias [3].
Wahhabism and Salafism: Movements aiming to return to the original, pure form of Islam [4]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [4].
The Muslim Brotherhood: Founded in the 1930s, the Brotherhood views jihad as an obligation and seeks to transform societies into Islamist states [7, 9].
Documents reveal their plan to transform America into an Islamist society, destroy Western civilization and make God’s religion victorious [10].
III. Key Figures
Muhammad: Considered the last prophet by Muslims; his life and teachings form the basis of Islam [2].
The Quran is believed to be the direct word of God as revealed to him [2].
Abu Bakr: The first caliph, successor to Muhammad [8].
Hassan al-Banna: Founder of the Muslim Brotherhood [7, 9].
Sayyid Qutb: An influential figure whose writings are embraced by jihadist groups [9, 11].
Osama bin Laden: A key figure in al-Qaeda, sought to destroy the United States [5, 12].
Abu Bakr Naji: An al-Qaeda theologian who wrote “The Management of Savagery”, a key strategic text for jihadist groups [13].
IV. Controversial Issues and Criticisms
Violence and Jihad: The concept of jihad is often used to justify violence and terrorism [5, 7, 14].
There is debate over whether jihad refers to an inner struggle for good or an external physical struggle [5, 6, 15].
Sharia Law in the West: Some fear the implementation of Sharia law in Western countries, noting the existence of Sharia courts and potential conflict with secular legal systems [4].
Treatment of Non-Muslims: Historically, non-Muslims in Muslim-controlled lands have sometimes been given a second-class status (dhimmi) and required to pay a tribute (jizya) [14].
There are documented instances of massacres and enslavement of non-Muslims by Muslim forces [16].
Freedom of Speech: Some Islamic texts advocate violence against those who disrespect Muhammad, creating tension with Western values [17-20].
Apologists: Some scholars and academics are accused of downplaying or ignoring the violent aspects of Islam by focusing on more peaceful interpretations [15, 21-23].
The Role of Western Foreign Policy: Some sources claim that the West is attempting to blame itself for terrorism, rather than acknowledging that the actions of terrorist groups are solely their own [14, 24].
V. Key Lies and Misconceptions
Claims such as “Islam translates to peace” are false; the more accurate translation is “submission” [25].
The Muslim Brotherhood is not a moderate, mainstream Islamic group [26].
Islam does not necessarily respect freedom of speech [17, 20].
Muslims do not all seek to live under Sharia [4].
VI. Strategies for Understanding
Primary Sources: It is crucial to study primary Islamic sources like the Quran and Hadith [6].
Understand Motivations: To understand enemies, one must understand their motivations and goals [27, 28].
Challenge Misconceptions: Challenge stereotypes and misrepresentations of Islam [23, 29].
VII. The Need for Action
Educated Citizenry: An informed public is necessary to combat misinformation and threats [28].
Truth: The public needs to be informed of the truth, despite claims from politicians and the media [28].
VIII. Specific examples of Islamist extremism
Al-Qaeda: This group began its war against the West long before the attacks of 9/11. Al-Qaeda operatives were responsible for the assassination of Massoud [30].
ISIS: This group has established what it calls a caliphate, and is responsible for numerous atrocities [8, 22].
The Muslim Brotherhood: This group seeks to establish an Islamist society in America [10, 31, 32].
IX. The Importance of Dabiq
The town of Dabiq in northwest Syria is the location where ISIS slaughtered a Western hostage [16]. The ISIS video warned that the conflict would continue until the crusader army was defeated in Dabiq [16].
This briefing document should help provide a better understanding of the complex issues surrounding Islam and Islamist extremism.
Understanding Islam: A Critical Inquiry
Here is a FAQ based on the provided sources and our conversation history:
Q: What are the main sources of Islamic teachings?
The primary sources are the Quran, believed by Muslims to be the direct word of Allah, and the Hadith, which are oral traditions recounting the life and practices of Muhammad [1]. Sharia law is derived from these sources along with Ijma (consensus of Muslim scholars) and Qiyas (reasoning by analogy) [2].
Q: What is Sharia law?
Sharia is a comprehensive code of conduct for Muslims, derived from the Quran and the Sunnah (the teachings and practices of Muhammad) [2, 3]. It covers all aspects of life, including family, business, and legal matters [4]. Some Muslims believe that Sharia is the supreme law, which should be followed by Muslims wherever they are [3].
Q: What is the concept of Jihad?
Jihad is often translated as “struggle” and has multiple interpretations [5, 6]. Some view it as an inner spiritual struggle to live virtuously [5], while others understand it as a physical struggle or war to defend or spread Islam [6, 7]. Some interpretations of jihad involve warfare against non-Muslims to establish the religion [6, 8]. Some Muslim leaders believe that jihad is an obligation from Allah on every Muslim [7].
Q: What is Wahhabism and Salafism?
These are movements within Islam that seek to return to the original, pure form of the religion, as practiced by the early generations of Muslims [9]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [9].
Q: What is the Muslim Brotherhood?
The Muslim Brotherhood is a transnational Islamist organization founded in the 1930s [7]. It aims to establish Islamic states and implement Sharia law. The Brotherhood is committed to a long-term “civilization jihad,” seeking to influence and infiltrate Western societies [10].
Q: What is the difference between Sunni and Shia Muslims?
The split between Sunni and Shia Muslims arose after the death of Muhammad, mainly over the issue of who should be his successor [11]. Sunnis believe that the successor should be chosen from among the prophet’s companions, while Shias believe that it should be someone from the prophet’s family, starting with Ali [11].
Q: Is Islam a peaceful religion?
While some Muslims and scholars emphasize the peaceful aspects of Islam, others point to passages in the Quran and Hadith that advocate for violence against non-believers [6, 8]. The word “Islam” translates to “submission,” not “peace” [12]. Some sources also claim that the concept of being “made victorious with terror” is a component of Islam [13].
Q: What is the view of free speech in Islam?
Some Islamic texts advocate for violence against those who disrespect Muhammad or Islam [14, 15]. This creates tension with Western notions of free speech [16-18]. Some Muslims believe that it is necessary to suppress speech that casts Islam in a bad light [19].
Q: How does Islamist extremism affect the West?
Islamist extremist groups like al-Qaeda and ISIS have carried out numerous terrorist attacks in the West [20]. The Muslim Brotherhood aims to infiltrate Western societies and establish Islamic enclaves [10, 21]. Some Muslims living in the West may believe that Sharia law is superior to secular law and may attempt to establish their own courts [22, 23].
Q: What are some common misconceptions about Islam?
Some common misconceptions include:
That Islam means peace [12]
That Islam respects freedom of speech [16]
That all Muslims support or seek to live under sharia law [4, 22]
That poverty or a lack of jobs is the root cause of terrorism [24, 25]
That the Muslim Brotherhood is a moderate organization [10, 21]
Many believe that claims that Islam is a religion of peace are lies used to mislead people [26].
Q: How should the West respond to Islamist extremism?
The sources suggest that the West must:
Understand the ideology and motivations of Islamist groups [27, 28]
Study primary Islamic texts like the Quran and Hadith [1]
Avoid self-blame and recognize that Islamist violence is often driven by religious motivations [25]
Challenge misrepresentations of Islam and the use of politically correct language [29]
Recognize the importance of the truth as it relates to the motives and goals of radical Islamic groups [27]
Understanding Islam: A Critical Inquiry
Here is a FAQ based on the provided sources and our conversation history:
Q: What are the main sources of Islamic teachings?
The primary sources are the Quran, believed by Muslims to be the direct word of Allah, and the Hadith, which are oral traditions recounting the life and practices of Muhammad [1]. Sharia law is derived from these sources along with Ijma (consensus of Muslim scholars) and Qiyas (reasoning by analogy) [2].
Q: What is Sharia law?
Sharia is a comprehensive code of conduct for Muslims, derived from the Quran and the Sunnah (the teachings and practices of Muhammad) [2, 3]. It covers all aspects of life, including family, business, and legal matters [4]. Some Muslims believe that Sharia is the supreme law, which should be followed by Muslims wherever they are [3].
Q: What is the concept of Jihad?
Jihad is often translated as “struggle” and has multiple interpretations [5, 6]. Some view it as an inner spiritual struggle to live virtuously [5], while others understand it as a physical struggle or war to defend or spread Islam [6, 7]. Some interpretations of jihad involve warfare against non-Muslims to establish the religion [6, 8]. Some Muslim leaders believe that jihad is an obligation from Allah on every Muslim [7].
Q: What is Wahhabism and Salafism?
These are movements within Islam that seek to return to the original, pure form of the religion, as practiced by the early generations of Muslims [9]. They often reject modern interpretations and emphasize strict adherence to early Islamic texts [9].
Q: What is the Muslim Brotherhood?
The Muslim Brotherhood is a transnational Islamist organization founded in the 1930s [7]. It aims to establish Islamic states and implement Sharia law. The Brotherhood is committed to a long-term “civilization jihad,” seeking to influence and infiltrate Western societies [10].
Q: What is the difference between Sunni and Shia Muslims?
The split between Sunni and Shia Muslims arose after the death of Muhammad, mainly over the issue of who should be his successor [11]. Sunnis believe that the successor should be chosen from among the prophet’s companions, while Shias believe that it should be someone from the prophet’s family, starting with Ali [11].
Q: Is Islam a peaceful religion?
While some Muslims and scholars emphasize the peaceful aspects of Islam, others point to passages in the Quran and Hadith that advocate for violence against non-believers [6, 8]. The word “Islam” translates to “submission,” not “peace” [12]. Some sources also claim that the concept of being “made victorious with terror” is a component of Islam [13].
Q: What is the view of free speech in Islam?
Some Islamic texts advocate for violence against those who disrespect Muhammad or Islam [14, 15]. This creates tension with Western notions of free speech [16-18]. Some Muslims believe that it is necessary to suppress speech that casts Islam in a bad light [19].
Q: How does Islamist extremism affect the West?
Islamist extremist groups like al-Qaeda and ISIS have carried out numerous terrorist attacks in the West [20]. The Muslim Brotherhood aims to infiltrate Western societies and establish Islamic enclaves [10, 21]. Some Muslims living in the West may believe that Sharia law is superior to secular law and may attempt to establish their own courts [22, 23].
Q: What are some common misconceptions about Islam?
Some common misconceptions include:
That Islam means peace [12]
That Islam respects freedom of speech [16]
That all Muslims support or seek to live under sharia law [4, 22]
That poverty or a lack of jobs is the root cause of terrorism [24, 25]
That the Muslim Brotherhood is a moderate organization [10, 21]
Many believe that claims that Islam is a religion of peace are lies used to mislead people [26].
Q: How should the West respond to Islamist extremism?
The sources suggest that the West must:
Understand the ideology and motivations of Islamist groups [27, 28]
Study primary Islamic texts like the Quran and Hadith [1]
Avoid self-blame and recognize that Islamist violence is often driven by religious motivations [25]
Challenge misrepresentations of Islam and the use of politically correct language [29]
Recognize the importance of the truth as it relates to the motives and goals of radical Islamic groups [27]
A History of Islam and Islamist Extremism
Here is a timeline of key events and developments related to Islam and Islamist extremism, based on the provided sources:
Early Islam (c. 609-732 AD)
c. 609 AD: Muhammad receives his first revelations in a mountain cave near Mecca [1].
c. 610-632 AD: Muhammad begins to preach the word of God, and his revelations are memorized or written on fragments, but not yet compiled into a complete written Quran [2, 3].
c. 622 AD: Muhammad and his followers move to Medina, marking the beginning of the Islamic calendar. Islam becomes a political and military force [4].
c. 632 AD: Death of Muhammad, leading to the selection of Abu Bakr as the first Caliph [5].
632-732 AD: Islamic conquest and conversion spreads, reaching as far north as France, where their advance is stopped by Charles Martel at the Battle of Tours [3, 6].
The Islamic Golden Age and Subsequent Decline (c. 700-1800)
700-1250 AD: The Islamic Golden Age, marked by advancements in learning and science [7].
c. 1200 AD: Islam has enjoyed nearly half a millennium of continuous expansion since the time of Muhammad [6].
1200-1798 AD: The Islamic world begins to decline, and the Ottoman Empire is eventually surpassed by European powers [8].
1798: Napoleon’s invasion of Egypt [9].
Rise of Modern Islamist Ideologies (18th-20th Centuries)
Late 18th Century: The rise of Wahhabism, calling for a return to the pure Islam of the early generations [10].
19th Century: The Ottoman Empire declines, and European powers exert control in the Middle East [8].
Early 20th Century: The Ottoman Caliphate collapses (1924), leaving the Muslim world without a single leader. The lands of the former Caliphate are divided by Western powers [11].
1920s-1930s: The rise of the Muslim Brotherhood in Egypt, founded by Hassan al-Banna, who taught that misery was caused by two things: Western influence and the Jews [12].
Mid to Late 20th Century
1947: The British mandate expires in Palestine leading to the creation of Israel. [13]
1980s: The mujahedeen in Afghanistan, backed by the US, fight the Soviet Union. This period is considered to be a key moment in the development of the Islamist movement [14].
The Rise of al-Qaeda and Islamist Terrorism (Late 20th – Early 21st Century)
1980s-1990s: Osama bin Laden emerges as a key figure in al-Qaeda, which begins its war against the West [15].
1981: Anwar Sadat, president of Egypt, is assassinated by members of the Muslim Brotherhood [16].
2000-2003: Al-Qaeda’s “Phase I: The Muslim Awakening” of their twenty-year plan, beginning with 9/11 and aimed at provoking the West [17].
2001: Al-Qaeda is responsible for the 9/11 attacks [14, 17].
2003-2006: Al-Qaeda’s “Phase II: Opening Eyes”, using propaganda and battlefield victories to reawaken Muslims and return them to the foundations of their faith [17].
2004: Publication of “The Management of Savagery” by Abu Bakr Naji, a key strategic text for jihadist groups [18, 19].
The Rise of ISIS and Continued Conflict (2010-Present)
2011: Unrest in the Middle East leads to the toppling of Hosni Mubarak in Egypt. This period became known as the Arab Spring [16].
2011: Qaradawi issues a fatwa outlining the Islamic standard for jihad [20].
2013: Al-Qaeda predicted that a new Islamic government would form a Caliphate, which would occur by 2016 [21].
2014: The Islamic State (ISIS) declares itself a Caliphate, adopting al-Qaeda’s ideology [21].
2014-present: ISIS commits atrocities in its controlled territories, broadcasting executions and using the Quran and Sharia to justify its actions [22, 23].
2015: The Charlie Hebdo massacre in France leads to further media self-censorship [24]. The Islamic State continues to be ground zero for crimes against humanity [22].
2000-2020: Al-Qaeda’s twenty-year plan, which included the establishment of an Islamic Caliphate, was scheduled to be completed by the year 2020 [25-27].
Ongoing Issues
Present Day: The struggle continues between those who seek to moderate Islam and those who seek to impose a totalitarian and fundamentalist form of the religion [28]. Some fear that the West is being infiltrated by radical Islamist groups [29].
This timeline highlights the key historical developments and the ongoing struggle between various factions of Islam, from its early days to the present. It also underscores the continuing threat posed by Islamist extremist groups.
A Concise History of Islam
Islam’s history is marked by periods of expansion, cultural flourishing, and internal conflict, and is characterized by a unique relationship between religion and political power [1-3].
Early Expansion (7th-8th Centuries):
The religion began in Mecca with the revelations of Muhammad [4].
After facing opposition in Mecca, Muhammad and his followers migrated to Medina, where Islam became a political and military force [3]. This event marks the beginning of the Islamic calendar [3].
Following Muhammad’s death, the Islamic community rapidly expanded through conquest and conversion [5].
By 732, Islamic expansion had reached into France, where it was halted at the Battle of Tours [4, 5].
The Islamic Golden Age (c. 700-1250):
This period saw significant advancements in science, mathematics, and philosophy [6].
Muslims translated and preserved the works of Greek philosophers like Aristotle and Plato [7].
However, this era was not without conflict, as there were sporadic bouts of violence between Muslims and religious minorities [7].
The flourishing of Islam during this period was based on military and trading power and cultural reappropriation [8].
Decline and the Rise of Islamist Ideologies (c. 1250-1924):
The Caliphate, the political and religious leadership of the Islamic world, gradually declined [9].
The Islamic world was surpassed by Western powers [10].
The Ottoman Empire, the last major Caliphate, was known as the “sick man of Europe” before it was dismembered after World War I [11, 12].
In 1924, the Caliphate was abolished by the secular Turkish Republic, leaving the Muslim world without a single leader [11].
The fall of the Caliphate is considered a tragedy by radical Islamists, who seek to restore it [11].
The loss of the Caliphate led to a push to revive Islam, and a belief that it is a total system that should include a political vision and social order [13].
The Muslim Brotherhood was founded in 1928 to restore the Caliphate and impose Islamic law on all nations [14].
The Rise of Modern Islamist Movements (20th-21st Centuries):
The creation of Israel and the loss of Arab lands became propaganda tools for those who saw Islam as the solution to the world’s problems [15].
The 20th century saw the rise of modern Islamist ideologies, including Salafism and Wahhabism which seek to return to the original, pure form of Islam [15].
The Soviet war in Afghanistan in the 1980s was a key moment for the development of the Islamist movement. The US supported the Mujahideen in Afghanistan [16].
Al-Qaeda, founded by Osama bin Laden, launched a war against the West [17].
The 9/11 attacks in 2001 marked a turning point in the relationship between the West and radical Islamists [17].
ISIS declared a new Caliphate in 2014, committing atrocities and seeking to expand its territory [18].
Key Themes in Islamic History
The concept of Dar al-Islam (house of Islam) and Dar al-harb (house of war): This division of the world into Muslim lands and non-Muslim lands has influenced the relationship between Islam and the rest of the world [19].
The inseparability of religion and politics: Unlike Christianity, where a separation of church and state developed over time, Islam has historically been associated with political power and conquest [2, 3].
The importance of the Quran and Hadith: These texts are regarded as the ultimate authority for Muslims and have been used to justify various actions throughout history [20].
The ongoing struggle between moderate and extremist interpretations of Islam: This tension has existed throughout Islamic history [21]. Some seek a classically liberal approach recognizing faith as something between God and the individual, while others seek to impose Islamic law on the world [21].
This history reveals that Islam is not a monolithic entity, but rather a diverse religion with various interpretations and movements. The tension between these interpretations continues to shape the Islamic world and its relationship with the West today [21].
Sharia Law: An Overview
Islamic law, known as Sharia, is a complex system of rules and guidelines derived from the Quran and the teachings of Muhammad [1, 2]. It is not just a legal code, but an all-encompassing way of life [1]. Sharia is meant to be a pathway to God’s will [1, 3].
Sources of Sharia:
Quran: The central, sacred text of Islam, believed to be the word of God as revealed to Muhammad [4].
Sunna/Hadith: The example and practices of Muhammad’s life, as recorded in oral traditions [4].
Ijma: The consensus of Muslim scholars [4].
Qiyas: Reasoning by analogy, which establishes new precedents in areas where the Quran and Hadith are unclear [4].
Key Aspects of Sharia:
Sharia covers a wide range of matters, including crime, politics, economics, and personal matters such as sexuality, diet, hygiene, prayer, and fasting [5]. It is intended to guide all aspects of life [3].
Sharia is considered by some to be the supreme law over everything and everyone, regardless of where they live [3].
Sharia is not a static set of rules; there are varying interpretations of Sharia [5-7]. Different schools of legal thought emerged after Muhammad’s death as scholars debated the meaning of the Quran and Hadith [8].
Sharia is viewed by many Muslims as a religious imperative [9]. Some believe that living under Sharia is a defined religious obligation [9, 10]. Muslims are expected to follow Sharia, wherever they live, and it must take precedence over the laws of man [7].
Some Muslims believe that the entire Muslim community must live under Sharia [11].
Some Islamic scholars believe that no other sovereign or authority is acceptable to a Muslim unless it guarantees the application of Sharia in its entirety [4].
Many Muslims believe that Sharia is the answer to the world’s problems and represents the holistic worldview of Muhammad and the Quran [12].
Sharia and Governance:
Sharia includes a “program for government,” which is why Islam has been a political force since its beginning [2].
Historically, there has been no separation of church and state in Islam, and caliphs were both religious and political leaders [1].
Sharia law developed a set of rules, laws, and traditions for non-Muslims, who were often treated as second-class citizens if they survived initial waves of conquest [13].
Some interpretations of Sharia call for Muslims to continuously wage war against non-Muslims until Islam establishes supremacy over all other religions [14].
Sharia and Punishment:
Sharia prescribes punishments for crimes considered to be against God, called hudud, including theft, adultery, and apostasy. Punishments range from lashes to banishment to death [15].
According to some interpretations of Sharia, theft may be punished by amputation of a hand [8, 15], and adultery is punishable by death by stoning [8, 16].
Apostasy, or abandoning Islam, is considered the most severe crime in Sharia, and can be punished by death [17].
Blasphemy, or anything seen as insulting to God or Muhammad, is also considered a severe crime, with punishments ranging from fines to amputation to hanging or beheading [8].
Sharia and Non-Muslims
Non-Muslims were sometimes allowed to retain their faith if they paid a tribute called a jizya, and were considered “protected” or “guilty” people (dhimmi) [13].
In some interpretations of Sharia, only “People of the Book” (Jews and Christians) are allowed to live in exchange for paying the jizya, and other non-Muslims must either convert to Islam or be killed [14].
In addition to paying the jizya, non-Muslims were required to acknowledge their position as second class citizens, and sometimes had to wear distinctive clothing [18].
Sharia in the Modern World:
Many Muslims around the world support the implementation of Sharia as the official law in their countries [12]. Some polls show that a large majority of Muslims in some countries favor making sharia the official law [9, 12, 16].
Some groups seek to impose Sharia on the entire world. [19, 20]
There are increasing instances of Sharia law coming into conflict with Western legal systems [21]. For example, some courts in the West have had cases where the husband claimed that it was his right to have sex with his wife at any time under Sharia law, or that a woman’s testimony should be worth half of a man’s [8, 21].
There is concern that some groups are trying to introduce Sharia into the judicial system in the West [22].
Some Muslim leaders have set up their own courts that follow Sharia, and some of these leaders have expressed support for harsh punishments such as cutting off the hands of thieves [23, 24].
Different Interpretations of Sharia:
There are varying interpretations of Sharia, leading to different practices across the Islamic world [5, 6, 25].
Some argue that Sharia is flexible and can be adapted to different political systems and cultures [25].
Others argue that Sharia is an eternal, unchangeable system that must take precedence over all other laws [7].
Many moderate Muslims believe that Sharia is personal religious law and moral guidance, but some groups have a literalist and absolutist view that believes Sharia should be imposed on everyone everywhere [20, 25].
It is important to note that there is no one “Sharia”; the term refers to a body of law and tradition interpreted differently across time and by different groups. It is this range of interpretations that forms the basis of both moderate and radical Islam.
Jihad: Interpretations and Justifications
Jihad is a complex concept with multiple interpretations, ranging from a personal spiritual struggle to a physical war against non-believers [1-5].
Multiple Interpretations of Jihad:
Some interpretations of Jihad focus on the internal struggle to be a better Muslim [1, 2, 4, 5]. This can include striving for virtue, doing good works, and taking personal responsibility [1, 4, 5].
Some scholars and Muslims view Jihad as a personal commitment to service, patience, and taking the higher road [2, 4].
Other interpretations view Jihad as a physical war against non-believers, and a holy duty for Muslims [6-10].
Some Muslims consider Jihad to be a legitimate tenet of Islam, meaning to purify oneself or one’s community [2].
Many Muslims and Islamic scholars consider the more correct definition of jihad to be the inner struggle to do good and follow God’s teachings [2].
Jihad as Holy War:
The Quran outlines the Islamic duty to make war upon non-Muslims [6]. Specifically, Sura 9, verse 29, explains the duty to fight those who do not believe in Allah, the Last Day, or forbid what has been forbidden by Allah and his messenger [6]. It also mentions fighting those who do not acknowledge Islam among the People of the Scripture (Jews and Christians) until they pay the Jizyah with willing submission and feel subdued [6, 11].
Sura 47, verse 4, sanctions taking captives as spoils of war [7]. It orders Muslims to continue Jihad against disbelievers until they embrace Islam or come under Muslim protection [7].
Sura 2, verse 154, states that Allah will reward holy warriors who fight on his behalf [8].
Some interpretations of Jihad involve the use of violence, crudeness, terrorism, frightening others, and massacring [12].
Some scholars believe that Jihad is the most merciful method for all created things and the most sparing of the spilling of blood [13].
Some Islamic scholars have stated that war is the real basis of relations between Muslims and non-Muslims, and that the infidelity of non-Muslims is the cause of such war [14].
Classical Islamic scholars have defined Jihad as a holy war, contrasting it with other religions where war is only for purposes of defense [10].
Some interpretations of Jihad emphasize the need to convert everyone to Islam by persuasion or by force [10].
Some Islamic scholars believe that Muslims are obligated to raid the lands of infidels, occupy them, and exchange their system of governance for an Islamic one [15].
Some believe that the objective of Islamic Jihad is to eliminate un-Islamic systems of rule and establish an Islamic system in its place [16].
Some Muslims believe that the goal of Islam is to spread its system of law across the world; therefore, any opposition to spreading Islamic law could be defined as a defensive act [17].
Some interpret Jihad as a movement aimed at preventing enemies from forcing their hegemony over land and people through violence that takes away freedom, kills people, and usurps wealth [18].
Jihad is sometimes interpreted as confronting violence with violence and force with force [18].
Jihad and its Justifications:
Some believe that disbelief alone is enough to justify murder [19].
Some Muslims believe that those who wage war against Allah and his messenger should be killed, crucified, have their hands and feet cut off, or be exiled [20].
Some also see “mischief in the land” as a justification for violence, with “mischief” referring to various types of evil [19].
Some interpretations of jihad see it as a way of extending the sovereignty of God’s law throughout the world [21].
“Defensive Jihad”
Some apologists for Jihad argue that, according to Islamic law, Allah will only countenance a “defensive” jihad, and that jihad is only justifiable once Muslim lands are attacked or Muslims are persecuted [22].
However, the definition of “defensive” can be broad. For example, some believe that if Muslims are not permitted to live according to Sharia law, it could be considered persecution and justification for defensive jihad [23].
Some have also used the concept of “defensive jihad” to justify attacks that could be seen as offensive, such as terrorist attacks [17].
Some have defined defensive jihad as a movement that prevents enemies from forcing their hegemony over land and people by violence that eliminates freedom, kills people, and usurps wealth [18].
Jihad and Motivation
Jihad must be done in the cause of Allah [24].
Anger, or worldly motivations, are not sufficient reasons for a Muslim to engage in jihad [25, 26].
Some believe that those who fight for reasons of anger or worldly emotions will not receive a heavenly reward [25, 26].
Modern Interpretations
Some Muslims and Islamic scholars are urging a careful scrutiny and revision of traditional understandings of jihad [14].
Some Muslim groups such as the Muslim Brotherhood are committed to a “civilization jihad,” a long-term plan to influence and infiltrate Western societies and destroy Western civilization from within [27-29].
Some groups believe that they will conquer Europe and America not through the sword but through dawa, which is the principal means of the Muslim Brotherhood’s civilization jihad [28].
It is important to note that the concept of jihad is not monolithic and has been interpreted and used in many different ways throughout history.
ISIS and al-Qaeda: A Comparative Analysis
ISIS and al-Qaeda are both radical Islamist terrorist groups that share a common goal of establishing a global Caliphate under Sharia law, but they have distinct origins, strategies, and organizational structures [1-4].
Shared Ideology:
Both groups adhere to a supremacist political ideology, known as Islamism, which seeks to impose Sharia law on the world [1, 5].
They believe that Islam is not a religion of peace, but rather a religion of war [6].
Both groups believe that they are charged with playing an active role in bringing about the end times [7].
They both seek to replace the world order of sovereign nation-states with a new world order divided between the Caliphate and the Muslim community of believers, and the unbelievers [8].
They believe in the concept of dar al-Islam (house of Islam) versus dar al-harb (house of war, or the rest of us) [9].
Both groups believe that their actions are justified by their interpretation of Islamic texts [10].
Both groups believe that they are the true protectors of Islam [11].
Both groups are focused on expanding their power to the entire planet [12].
Both see the imposition of Sharia law as an imperative [4].
Origins and Evolution:
Al-Qaeda emerged as a terrorist organization, while ISIS evolved from al-Qaeda’s Iraq branch and became a quasi-government controlling territory [13, 14].
Al-Qaeda’s origins can be traced back to the fight against the Soviet Union in Afghanistan. It later became a global terrorist network led by Osama bin Laden [15, 16].
ISIS grew out of the chaos of the Syrian Civil War and the power vacuum in Iraq after the withdrawal of U.S. forces [13, 17, 18].
Al-Qaeda had a twenty-year plan to install a Caliphate, and the 9/11 attacks were part of that plan [15].
Organizational Structure and Leadership:
Al-Qaeda has evolved from a terrorist organization to an ideological movement to which ISIS and other jihadi groups pledge allegiance [19].
Al-Qaeda is no longer seen as having a command-and-control structure like a mini-Pentagon, but rather a movement with adherents that are self-recruited and can spring up anywhere [19].
ISIS declared itself a Caliphate in 2014, establishing a physical territory and governing structure in parts of Syria and Iraq [20].
ISIS’s self-appointed leader, Abu Bakr al-Baghdadi, declared himself Caliph and changed his name to include “Muhammad,” believing himself to be the Mahdi [21].
Tactics and Strategies:
Al-Qaeda primarily operates as a terrorist organization conducting attacks on Western targets [8, 15, 22].
ISIS uses a combination of terrorism and conventional warfare to expand and control territory [18, 20, 23].
ISIS is known for its brutality, using beheadings, massacres, and enslavement as methods of control and intimidation [21, 23].
Both groups use propaganda, social media, and videos to spread their message and recruit new members [21, 24-26].
Both groups use cyberattacks to target America’s economic might [2].
Goals and Objectives:
Al-Qaeda’s goal was to re-establish the Caliphate and return Islam to global dominance [15].
ISIS’s objective is to establish a global Caliphate and impose Sharia law on all survivors, believing it is their duty to bring about the end times [7, 27].
ISIS believes it will be a key agent of the coming apocalypse [28].
ISIS wants to engage in a final confrontation with the West that will result in World War III [29].
Both groups believe the West will lose its will to fight, allowing the Caliphate to grow in strength and territory [2].
Relationship and Merging of the Groups:
ISIS grew out of Al-Qaeda in Iraq [3, 13].
There is evidence that al-Qaeda and ISIS are merging [3].
Al-Qaeda’s ideology and terrorist tactics went mainstream after ISIS declared the Islamic State [14].
The declaration of the Caliphate by ISIS was a goal al-Qaeda had predicted a decade earlier [14].
Specifics about ISIS
ISIS’s capital is al-Raqqa in eastern Syria [18].
ISIS has cells operating in more than a dozen countries with outposts where it governs pockets of territory [30].
Some ISIS members believe that their leader, al-Baghdadi, is the Mahdi himself [21].
ISIS considers the village of Dabiq to be the location of the final battle between the forces of Islam and the infidels [17, 27].
ISIS propaganda refers to the United States as the “forces of Rome” who will be defeated at Dabiq [27].
ISIS believes that after this battle, there will be an open road to Istanbul and Europe beyond [27].
ISIS has a digital magazine called Dabiq [24].
ISIS has razed the birthplace of human civilization in Iraq and Syria to build a new Caliphate [31].
ISIS destroys ancient artifacts because they consider them “worthless,” even if they are worth billions of dollars [31].
Specifics about Al-Qaeda
Al-Qaeda’s twenty-year plan, which began in 2001, has seven phases [15, 16].
Al-Qaeda’s plan included drawing America into war in Afghanistan and Iraq, toppling secular governments, and creating an Islamic Caliphate [32].
Al-Qaeda’s plan predicted the Arab Spring, when secular governments would topple [32].
Al-Qaeda’s plan included a special focus on Syria, because Syria is home to Dabiq, and it is the doorstep to toppling Jordan and Israel [17].
Differences in Tactics
While both groups use violence, ISIS is known for extreme brutality, including beheadings, crucifixions, and mass executions [23, 33, 34].
ISIS uses savagery as a central method of ruling to shock and deter. It may alienate some potential supporters, but it forces many more into submission [21].
Response to the Groups
Some governments recognize the threat posed by both groups, and see no distinction between them [35].
Some governments and media outlets do not acknowledge the connection between Islam and the actions of these groups, labeling them as “not Islamic” [36-38].
The U.S. administration initially downplayed the threat of ISIS, calling them a “JV team” [37].
In conclusion, while ISIS and al-Qaeda share the ultimate goal of a global Caliphate under Sharia law, they have evolved with different strategies and methods. Al-Qaeda has become an ideological movement with decentralized control, while ISIS has established itself as a quasi-government with control of territory. Both groups use violence and propaganda to spread their message and achieve their goals [19, 20].
The Caliphate: Goals, History, and Challenges
The overarching goal of a Caliphate is to establish a global Islamic state governed by Sharia law [1-3]. This objective is central to the ideologies of various radical Islamist groups [4, 5], including ISIS and al-Qaeda [6, 7].
Here are specific goals and aspects associated with the Caliphate as described in the sources:
Unification of Muslims: The Caliphate aims to unite all Muslims under a single political and religious authority, transcending national borders and secular laws [2, 8]. The vision is to erase the boundaries of nation-states and create one Muslim community, the umma [2, 9].
Implementation of Sharia Law: A key objective is to enforce Sharia law in all aspects of life, encompassing legal, social, and political systems [2, 8]. Sharia is viewed as the inalterable law of God [1, 5]. The Caliphate sees its mission as “compelling the people to do what the Sharia (Allah’s law) requires of them” [10].
Global Expansion: The Caliphate seeks to expand its territory and influence worldwide [1, 11]. This is based on the concept that dar al-harb (house of war, referring to non-Muslim lands) should shrink, giving way to a global Caliphate of believers [2, 11, 12].
Rejection of Western Influence: The Caliphate seeks to reverse the perceived decline of the Islamic world by rejecting Western innovations and traditions, such as secular constitutions and nation-states [2, 13]. It aims to restore Islam to what is seen as its original, pure form [5, 14].
Establishment of an Islamic State: The Caliphate aims to set up an Islamic state to faithfully implement Sharia law as Muhammad and the first four rightly guided caliphs did [2].
Role in the End Times: Many Islamists believe that establishing the Caliphate is a necessary step to bring about the return of the Mahdi and the Day of Judgment [15, 16]. The Caliphate is seen as a sign of the impending end times, giving meaning to those who seek it [15, 17]. Some ISIS members believe that their leader, Abu Bakr al-Baghdadi, is the Mahdi [17].
Total Submission to Allah: The Caliphate requires complete submission to Allah, with Muslims acknowledging their purpose to carry out the commands of Allah, establish His religion, and refer to His law for judgment [1, 10].
Confrontation with the West: The Caliphate seeks a final confrontation with the West that they hope will result in World War III [18]. They believe that the West will lose its will to fight, allowing the Caliphate to grow in strength and territory [19].
Establishing a new world order: The Caliphate seeks to replace the world order of sovereign nation-states with a new world order divided between the Caliphate and the Muslim community of believers, and the unbelievers [12].
Rejection of National Citizenship: The Caliphate does not recognize national citizenship or the borders of countries, and uses terms like Syria and Iraq that have no meaning [8].
Historical and Ideological Context:
The concept of the Caliphate is rooted in Islamic history, dating back to the time of Muhammad and the early Islamic empires [4, 20].
The Caliphate expanded from Spain to India by the beginning of the eighth century A.D. [21].
The abolition of the Ottoman Caliphate in 1924 is seen as a tragedy by radical Islamists, who seek to reestablish it [6, 22].
The desire to create a Caliphate has been a long-standing goal for groups like al-Qaeda and the Muslim Brotherhood [6, 23].
The rise of ISIS and its declaration of a Caliphate in 2014 has galvanized many Islamists around the world [24].
Reestablishing the Caliphate was a goal for Osama bin Laden and al-Qaeda [6].
Specific Actions and Beliefs of the Caliphate:
The Caliphate considers those who are not true Muslims to be enemies [8].
The Caliphate imposes harsh punishments on those who don’t follow Sharia Law [25].
The Caliphate uses violence and brutality to instill fear and force submission [6, 17, 26].
They believe that they are fulfilling prophecies of Muhammad about the coming Day of Judgment [17].
Many radicals believe that the Caliphate will be ruled from Jerusalem [27]. They see Jordan as the eastern gate to Israel [27].
The Caliphate sees itself as a divinely ordained political entity destined to spread to the corners of the earth [9].
Challenges to the Idea of the Caliphate:
Many Muslims do not recognize the legitimacy of the Caliphate established by ISIS [9].
Some view the idea of a Caliphate as a fanciful dream, or an absurd delusion that will never happen [27, 28].
Some Western political and media figures have downplayed the threat of the Caliphate, dismissing it as unrealistic [28-30].
In summary, the Caliphate’s goal is to establish a global Islamic state under Sharia law, uniting all Muslims, rejecting Western influence, and fulfilling prophecies about the end times [16]. This is a core objective for many radical Islamist groups, and it involves the use of various tactics, including violence, propaganda, and political action [5, 9].
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
These articles from “Al Riyadh” newspaper cover a range of topics from early April 2025. Several pieces discuss international relations and trade, including Saudi Arabia’s condemnation of Israeli actions and the European Union’s response to potential US tariffs. Economic news includes analysis of the Saudi stock market, oil price fluctuations due to global factors, and challenges facing the petrochemical industry. Other articles highlight Saudi Arabia’s domestic initiatives in human capabilities development, project management, digital transformation in education and media, and efforts to support the Arabic language. Finally, there are reports on local events, sports news, and community updates, including aid efforts for Gaza and cultural events in Saudi Arabia.
لتصدي للتحايل بربط التأشيرة بحجوزات الطيران لمدة البرامج وإقامة المعتمرين
Study Guide: Analysis of “20734.pdf” Excerpts
I. Key Themes and Concepts:
The Israeli-Palestinian Conflict: Understand the historical context, including UN Resolution 181 (1947), the 1948 Arab-Israeli War, and the displacement of Palestinians. Focus on the concept of the two-state solution and international support for it.
Saudi Arabia’s Foreign Policy: Analyze Saudi Arabia’s consistent stance on the Palestinian issue, its demand for a 1967 border-based independent Palestinian state with East Jerusalem as its capital, and its condemnation of Israeli actions. Note its emphasis on the Palestinian people’s right to self-determination.
International Reactions to the Conflict: Recognize the international community’s criticism of Israeli policies like settlement construction and the separation wall. Understand the call for recognition of a Palestinian state on 1967 borders by the UN Security Council member states that haven’t yet done so.
Economic News and Analysis: Understand the impact of international events (like potential US tariffs) on global and Saudi markets, including the oil sector. Note the analysis of defensive sectors during times of uncertainty and the reasons behind market fluctuations.
Saudi Arabia’s Domestic Developments: Be aware of various events within Saudi Arabia, including regional administrative appointments, conferences (e.g., Human Capability Initiative, Global Project Management Forum), and initiatives in education and culture (e.g., King Salman Global Academy for Arabic Language, Riyadh Art Week).
Global Trade and Tariffs: Understand the potential implications of increased tariffs and trade disputes, particularly the US-China trade tensions, and their effect on various economies and sectors.
The Role of Technology and Artificial Intelligence: Note the discussion on the increasing reliance on AI for analysis and decision-making and the potential risks associated with the decline of human critical thinking.
Sports and Cultural Events: Be aware of the coverage of local sports leagues, team performances, and cultural events like “Layali Dami Al-Saif” and the revival of traditional Najdi dances.
Social Issues and Humanitarian Concerns: Understand the reports on the humanitarian situation in Gaza, including food insecurity, restricted aid, and the psychological impact on children. Note the discussions around visa policies and expatriate worker issues.
What was the main outcome of UN Resolution 181 in 1947 regarding Palestine, and what significant event in 1948 resulted in the displacement of many Palestinians?
Describe Saudi Arabia’s official stance on the establishment of a Palestinian state, specifically mentioning the key conditions for establishing diplomatic relations with Israel.
According to the excerpts, what actions by Israel are frequently criticized by the international community and Saudi Arabia in relation to the Palestinian territories?
Explain the analysis provided in the text regarding the performance of “defensive sectors” like telecommunications and food during times of economic uncertainty.
What was the focus of the Human Capability Initiative conference mentioned in the excerpts, and under whose patronage was it held?
Describe the potential negative consequences discussed in the text regarding the increasing global trade tensions and the imposition of tariffs, particularly by the US and China.
According to one of the opinion pieces, what is a potential danger associated with the increasing reliance on artificial intelligence for analysis and decision-making?
What was the significance of the “Layali Dami Al-Saif” event, and what broader cultural initiative was it part of in Jeddah?
Based on the excerpts, what are some of the key challenges faced by the population in Gaza, as reported by international organizations?
According to the excerpts, what is the primary goal of the King Salman Global Academy for Arabic Language’s collaboration with Indiana University?
«السوق السعودي».. تراجع حاد وسط هبوط بورصات العالم
III. Quiz Answer Key:
UN Resolution 181 called for the partition of Palestine into two states: one Jewish and one Arab. The 1948 Arab-Israeli War, which led to the establishment of Israel, resulted in the displacement and expulsion of hundreds of thousands of Palestinians.
Saudi Arabia’s stance is firm on the necessity of the Palestinian people obtaining their legitimate rights, demanding an independent Palestinian state based on the 1967 borders with East Jerusalem as its capital. It has stated there will be no diplomatic relations with Israel without recognition of this state and a withdrawal from the Israeli aggression on Gaza and the West Bank.
The international community and Saudi Arabia frequently criticize Israeli policies such as the construction of the separation wall, the building and expansion of settlements in Palestinian territories, and the ongoing incursions into Al-Aqsa Mosque. They uphold the rights of Palestinians, including their right to self-determination and independence.
The analysis suggests that during times of current uncertainty, defensive sectors like telecommunications and food are considered to be in a state of defense, implying they might be more stable or less affected by market downturns compared to other sectors.
The Human Capability Initiative conference, held under the patronage of the Crown Prince and Chairman of the Council of Ministers’ Committee for the Human Capability Development Program, focused on preparing for the future “beyond 2014” and enhancing human capabilities to adapt to rapid global changes.
The potential negative consequences of increased tariffs and trade disputes include higher prices for consumers, the possibility of a global trade war, and the risk of pushing economies around the world into recession. The US-China trade tensions, with retaliatory tariffs, exacerbate these concerns.
One opinion piece suggests that a potential danger of increasing reliance on AI is the decline of human critical thinking and the transformation of humans into obedient followers of machine decisions, potentially leading to intellectual extinction before digital superiority.
“Layali Dami Al-Saif” was a significant and celebratory intellectual gathering inaugurated by the Governor of Makkah, emphasizing Saudi Arabia’s cultural and literary values. It served as the launch of an exhibition titled “Layali fi Hubb Khalid Al-Faisal” as part of the “Jeddah Season 2025.”
Key challenges faced by the population in Gaza include severe food insecurity due to the continued closure of crossings and prevention of aid entry, the destruction of water infrastructure, and the repeated forced displacement amidst ongoing conflict, leading to psychological distress, particularly among children.
The primary goal of the King Salman Global Academy for Arabic Language’s collaboration with Indiana University is to train teachers of Arabic for non-native speakers using advanced educational methods, enhance their teaching abilities, and develop the skills of their learners.
“وزارة الحج والعمرة” تحدد 1 من ذي القعدة آخر موعد لمغادرة المعتمرين
IV. Essay Format Questions:
Analyze the consistency and key principles of Saudi Arabia’s foreign policy towards the Israeli-Palestinian conflict as presented in the provided excerpts. Discuss the potential impact of this stance on regional and international diplomatic efforts.
Critically evaluate the interconnectedness of global economic events, such as US tariff policies, and their potential ripple effects on the Saudi Arabian economy, particularly the oil and stock markets, as suggested by the text.
Discuss the significance of the various conferences and initiatives mentioned in the excerpts (e.g., Human Capability Initiative, Riyadh Art Week, King Salman Global Academy for Arabic Language) in the context of Saudi Arabia’s Vision 2030 goals for human capital development and cultural enrichment.
Explore the potential benefits and risks of the increasing integration of artificial intelligence into analysis and decision-making processes, drawing upon the arguments presented in the opinion piece regarding the future of human intellect.
Examine the humanitarian situation in Gaza as depicted in the excerpts, considering the roles and responsibilities of international actors and the long-term implications for the affected population.
حرس الحدود بالمدينة ينقذ 3 مواطنين تعطلت واسطتهم البحرية في عرض البحر
V. Glossary of Key Terms:
قرار 181 (Resolution 181): A United Nations resolution passed in 1947 that called for the partition of Palestine into two separate states, one Jewish and one Arab.
حل الدولتني (Two-State Solution): A proposed framework for resolving the Israeli-Palestinian conflict by establishing two independent states, one for Israelis and one for Palestinians, living side-by-side in peace and security.
حق تقرير المصير (Right to Self-Determination): The principle that a people should be able to freely decide their own political status and form of government without external influence.
الجدار الفاصل (Separation Wall): A barrier constructed by Israel in the West Bank, the route and impact of which are highly controversial and have been condemned by international bodies.
المستوطنات (Settlements): Israeli civilian communities established on land captured by Israel in the 1967 war, considered illegal under international law by many countries and organizations.
وكالة غوث وتشغيل اللاجئين الفلسطينيين (UNRWA – United Nations Relief and Works Agency for Palestine Refugees in the Near East): A UN agency that provides assistance and protection to Palestinian refugees registered in Jordan, Lebanon, Syria, the West Bank, and the Gaza Strip.
العمرة (Umrah): A voluntary Islamic pilgrimage to Mecca that can be performed at any time of the year, distinct from the annual Hajj pilgrimage.
الرسوم الجمركية (Tariffs): Taxes imposed by a government on imported or exported goods.
التحول المؤسسي والخدمي (Institutional and Service Transformation): A comprehensive process of organizational change aimed at improving efficiency, effectiveness, and the quality of services provided.
منظمة الأمم المتحدة للطفولة (UNICEF – United Nations Children’s Fund): A UN agency responsible for providing humanitarian and developmental aid to children worldwide.
الذكاء الاصطناعي (Artificial Intelligence – AI): The theory and development of computer systems able to perform tasks that normally require human intelligence, such as visual perception, speech recognition, decision-making, and translation between languages.
مبادرة القدرات البشرية (Human Capability Initiative): A program or conference focused on developing and enhancing the skills, knowledge, and potential of individuals, often in line with broader national development goals.
الإرث الثقافي (Cultural Heritage): The legacy of physical artifacts and intangible attributes of a group or society that are inherited from past generations, maintained in the present, and bestowed for the benefit of future generations.
الرؤية (Vision) 2030: A strategic framework launched by Saudi Arabia with the goal of diversifying its economy, developing public service sectors, and enhancing its role in the international community.
قادة مصر والأردن وفرنسا يدعون إلى عودة فورية لوقف إطلاق النار في غزة
Al Riyadh Newspaper: April 7, 2025 – Key Themes
Briefing Document: Analysis of Provided Sources
This briefing document summarizes the main themes, important ideas, and key facts extracted from the provided excerpts of the Al Riyadh newspaper dated Monday, April 7, 2025. The articles cover a range of topics, including international relations, economic developments, local events, cultural initiatives, and social issues within Saudi Arabia and the wider region.
1. Palestinian Issue:
Two-State Solution Support: The Kingdom’s position remains consistent in supporting the legitimate rights of the Palestinian people, emphasizing the necessity of a two-state solution with an independent Palestinian state based on the 1967 borders, with East Jerusalem as its capital.
Condemnation of Israeli Policies: Saudi Arabia criticizes Israeli policies, including the construction of the separation wall and settlements, and affirms the Palestinians’ right to self-determination and independence.
No Diplomatic Ties Without Recognition: The Kingdom has informed the US administration that there will be no diplomatic relations with Israel unless the independent Palestinian state is recognized on the 1967 borders, East Jerusalem is its capital, and the Israeli aggression on the Gaza Strip ceases with the withdrawal of all Israeli occupation forces.
Call for International Recognition: The Kingdom reiterates its constant call to the international community, especially Security Council member states that have not yet recognized Palestine, to recognize the Palestinian state on the 1967 borders with East Jerusalem as its capital. This is to enable the Palestinian people to attain their legitimate rights and for a comprehensive and just peace to be achieved for all.
Condemnation of Al-Aqsa Mosque Incursion: Saudi Arabia strongly condemns the storming of the blessed Al-Aqsa Mosque by the Israeli National Security Minister under the protection of the occupation police and the expulsion of worshippers. It reiterates its denunciation of the continued blatant Israeli violations of the sanctity of Al-Aqsa Mosque.
Condemnation of Targeting UNRWA Clinic: The Kingdom also condemns the targeting by Israeli occupation forces of a clinic belonging to the United Nations Relief and Works Agency for Palestine Refugees in the Near East (UNRWA) in the Jabalia refugee camp in the northern Gaza Strip, denouncing the continued targeting by Israeli occupation forces.
Deteriorating Humanitarian Situation in Gaza: UNICEF reports on the severe food insecurity in the Gaza Strip due to the ongoing Israeli aggression and the continued closure of crossings, preventing the entry of medical aid, supplies, and nutritional supplements for 35 days. Over a million children in Gaza have been deprived of life-saving aid for more than a month, representing a flagrant violation of international humanitarian law.
Water Crisis in Gaza: The majority of water wells in Gaza are out of service, and the central desalination plant west of Gaza City is damaged, alongside power shortages. The municipality now relies by 70% on transported water in tankers, part of which is distributed in barrels on carts to areas not reached by the municipal water network. Israeli occupation deliberately targeted water facilities during the aggression, causing significant damage and widespread destruction of wells and networks, creating a severe crisis.
خبراء الأمم المتحدة لحقوق الإنسان يدعون إلى وضع حد للإبادة الجماعية في غزة
2. Saudi Arabia’s Internal Affairs and Vision 2030:
Eid Al-Fitr Greetings: Princes and officials received well-wishers on the occasion of Eid Al-Fitr in Riyadh and the Eastern Province.
Institutional and Service Transformation: The Emir of Hail emphasized that the next stage requires achieving institutional and service transformation in line with the objectives of the Kingdom’s Vision 2030.
Human Capabilities Initiative Forum: Riyadh will host the second edition of the Human Capabilities Initiative Forum from April 29 to May 1, 2025, under the patronage of the Crown Prince. The forum aims to unite international efforts, enrich dialogue, exchange expertise, and discuss ideas that enhance the readiness of human capabilities to cope with rapid global changes. Over 300 leaders, policymakers, and experts from various sectors will participate.
Global Project Management Forum: Riyadh will also host the fourth edition of the Global Project Management Forum from May 17 to 19, 2025, focusing on “The Next Generation in Project Management: Power of Operations, Power of Human Capital, Power of Technology.” The forum aims to discuss the future of project management, promote innovation, and strengthen the Kingdom’s position as a global leader in this vital field.
King Salman Medical City Training Center: The Saudi Commission for Health Specialties has accredited the training program in neurosurgery at King Salman Medical City in Madinah as a comprehensive training program.
Ministry of Education at Geneva International Exhibition of Inventions: The Ministry of Education will participate in the 2025 edition of the Geneva International Exhibition of Inventions, showcasing 134 inventions by Saudi talents, including students and companies, reflecting the Kingdom’s focus on national priorities, innovation, and development in line with Vision 2030.
Ehsan Platform Recognition: The Ehsan platform was recognized and honored for its outstanding services in achieving sustainable social impact, aligning with the objectives of Vision 2030.
King Abdulaziz Center for World Culture (Ithra) Participation: Ithra will participate in the Riyadh Art Week, showcasing the interaction between Saudi cultural heritage and global influences in contemporary art.
أسهم أوروبا تغلق عند أدنى مستوى في 14 شهرا بسبب الحرب التجارية
3. Economic Developments and Market Trends:
Stock Market Fluctuations: The Saudi stock market experienced fluctuations mirroring global market trends, particularly influenced by US President Trump’s announcement of imposing high customs tariffs on imports, raising fears of a negative impact on the global economy and trade disputes. An analyst noted that the Saudi market values remain fair and that impulsive selling could lead to significant investor losses. Defensive sectors like telecommunications and food are considered relatively safe during the current uncertainty.
Impact of US Tariffs: The US imposition of high customs tariffs on imports from several countries, including China and potentially the European Union, is a significant concern. This has led to retaliatory tariffs and increased global trade tensions, raising fears of inflation and a slowdown in economic growth. Experts predict US consumers will face higher prices, and European consumers will also feel the pressure.
Oil Price Decline: Oil prices fell significantly by 7% due to China’s increase in customs tariffs on American goods, escalating trade war fears and leading investors to anticipate a greater likelihood of recession. Major investment banks lowered their global oil demand growth forecasts.
US-EU Trade Tensions: The European Union is considering a unified response to the US tariffs, likely targeting $28 billion worth of American imports. There are fears that the escalating trade dispute could turn into a global trade war, increasing costs for economies and pushing consumers into recession.
“الصحة” تؤكد: التحول الصحي أسهم في رفع متوسط العمر المتوقع إلى 78.8 سنة
4. Regional Security and International Relations:
US Envoy’s Visit to Lebanon: The US Deputy Assistant Secretary of State for Near Eastern Affairs visited Lebanon and held meetings with top officials, including President Michel Aoun, to discuss the situation in southern Lebanon and other issues. This coincides with continued Israeli airstrikes on Lebanese territories despite the ongoing cessation of hostilities since November 27. The debate about the disarmament of Hezbollah has resurfaced.
Yemen Conflict: The Houthi group announced the killing and injury of six people in an American bombing in Saada governorate, the group’s main stronghold in northern Yemen. The US Central Command confirmed conducting strikes against Houthi missile sites. The Houthis also reported targeting a supply ship of the US aircraft carrier “Truman” with a ballistic missile and claimed to have disrupted “hostile attacks on Yemen” in the past hours, vowing to continue their operations until the aggression on Gaza stops and the blockade is lifted.
Iran-US Relations: Oman is reportedly mediating talks between Iran and the United States. The article also outlines key historical junctures in the long-standing rivalry between Tehran and Washington.
US Visa Restrictions on South Sudan: The United States imposed unprecedented visa restrictions on citizens of South Sudan, accusing the transitional government of not taking steps to address issues with its citizens who have been deported from the US.
الالمملكة تُشارك في أعمال الدورة 221 للمجلس التنفيذي لمنظمة اليونسكو
5. Social and Cultural Events:
Riyadh Art Week: Riyadh Art Week is taking place, featuring exhibitions, workshops, and interactive art displays across the capital, highlighting the dynamic contemporary art scene in Saudi Arabia.
“Layali Fi Hubb Khalid Al-Faisal” Exhibition: An exhibition titled “Layali Fi Hubb Khalid Al-Faisal” was inaugurated as part of the “Jeddah Season 2025,” celebrating the artistic and literary legacy of Prince Khalid Al-Faisal.
King Salman Global Academy for the Arabic Language Program in the US: The King Salman Global Academy for the Arabic Language, in cooperation with Indiana University in the United States, is organizing a specialized scientific program for Arabic language teachers of non-native speakers.
Abu Dhabi Arabic Language Centre New Index: The Abu Dhabi Arabic Language Centre announced a new index, “Arabic Language Strength Index,” to measure and track the community’s connection to the Arabic language.
البنك الدولي يشيد بريادة المملكة في تطوير تقنيات “تحلية المياه
6. Sports:
Saudi U-17 National Team Qualifies for FIFA U-17 World Cup: The Saudi U-17 national team qualified for the FIFA U-17 World Cup 2025 in Qatar after defeating Thailand 3-1 in the AFC U-17 Asian Cup qualifiers held in Taif.
Jeddah to Host AFC Basketball Asia Cup Draw: Jeddah will host the draw ceremony for the AFC Basketball Asia Cup, which will be held in Saudi Arabia in early August.
Al-Ahli Coach Linked to Bundesliga Club RB Leipzig: Reports suggest that Matthias Jaissle, the coach of Al-Ahli Saudi FC, is a potential candidate to take over as coach of RB Leipzig due to the poor ongoing results of the current coach, Marco Rose.
7. Opinion and Analysis:
The Saudi Role in International Mediation: An opinion piece highlights Saudi Arabia’s growing political standing and its potential to become a significant global mediator in international conflicts, especially in the Middle East, driven by Vision 2030.
The Impact of Artificial Intelligence on Human Thought: An article discusses the increasing reliance on artificial intelligence for analysis and decision-making, raising concerns about the potential decline of human critical thinking and the risk of humans becoming overly dependent on machines.
Critique of Al-Hilal Football Club Performance: A fan expresses disappointment with the recent performance of Al-Hilal football club, stating that the team no longer strikes fear in opponents and needs to address the level of some players.
8. Traffic Regulations and Safety:
General Directorate of Traffic Clarifies Enforcement Procedures: The General Directorate of Traffic clarified that vehicle impoundment or penalty enforcement will only occur after the expiry of the grace period stipulated by regulations (Article 75), emphasizing that fines are doubled only if payment is not made within the specified period. The system offers violators several options, including a 30-day grace period with a 25% discount if paid within that period, and the possibility of requesting a 90-day extension for payment within the first 15 days of the violation being recorded.
Citizens Demand Addressing Dangerous Afif/Qassim Road: Citizens and travelers are urging relevant authorities to address the dangerous state of the Afif/Qassim road, which has become a major artery but suffers from poor condition, potholes, and frequent truck traffic, leading to accidents. They are calling for the acceleration of the road dualization project.
9. Customs and Smuggling:
Saudi Customs Records 1071 Seizure Cases: Saudi customs outlets recorded 1071 seizure cases of prohibited items, including drugs, controlled substances, tobacco products, and monetary amounts, reflecting the ongoing efforts of the Zakat, Tax and Customs Authority to enhance security and protect society.
This briefing document provides a snapshot of the diverse issues and events covered in the provided excerpts from Al Riyadh newspaper, highlighting Saudi Arabia’s active engagement in regional and international affairs, its focus on achieving the goals of Vision 2030, and various local developments and social concerns.
Saudi Arabia: Global Events and Initiatives
FAQ on the Provided Sources
1. What are the key historical and ongoing issues concerning Palestine as highlighted in the sources?
The sources emphasize the 1947 UN Resolution 181 calling for the division of Palestine into two states and the subsequent 1948 Arab-Israeli War, which led to the displacement of hundreds of thousands of Palestinians. The international stance, supported by the Kingdom of Saudi Arabia, advocates for a two-state solution with an independent Palestinian state based on the 1967 borders, with East Jerusalem as its capital. The sources criticize Israeli policies such as building the separation wall and expanding settlements, while affirming the rights of Palestinians, including their right to self-determination and independence. The Kingdom of Saudi Arabia maintains that there will be no diplomatic relations with Israel without the recognition of an independent Palestinian state within the 1967 borders and the withdrawal of Israeli forces from the Gaza Strip. The continued Israeli incursions into Al-Aqsa Mosque and targeting of UNRWA facilities in Gaza are also condemned.
2. What is the Kingdom of Saudi Arabia’s position on the Palestinian issue and what actions does it advocate for?
The Kingdom of Saudi Arabia’s position on the Palestinian issue is firm and supportive of the legitimate rights of the Palestinian people, including their right to an independent state based on the 1967 borders with East Jerusalem as its capital. Saudi Arabia insists that there will be no diplomatic ties with Israel until an independent Palestinian state is recognized within these borders and the Israeli aggression against Gaza ends with a full withdrawal of its forces. The Kingdom consistently calls on the international community, particularly permanent members of the UN Security Council, to recognize the State of Palestine. It strongly condemns Israeli actions such as incursions into Al-Aqsa Mosque and attacks on Palestinian civilians and facilities, urging an end to these violations.
3. How did the Riyadh stock market and Saudi economy react to global economic events and trends mentioned in the sources?
The Riyadh stock market experienced a downturn, mirroring global market declines following concerns over potential US tariffs on imports announced by President Trump. This sparked fears of trade wars and negative impacts on the global economy. Despite the market fluctuations, Saudi economic analysts maintained that the Saudi market values remained fair and cautioned against impulsive selling, emphasizing the strong fundamentals of the Saudi economy, particularly the expected significant spending by tourists in 2024. Certain sectors like telecommunications and food were considered defensive in the face of economic uncertainty. The drop in oil prices, partly attributed to China’s retaliatory tariffs on US goods, also influenced the economic outlook.
4. What initiatives and events are being organized in Saudi Arabia to promote human capital development and innovation, as highlighted in the sources?
Saudi Arabia is actively investing in human capital development through initiatives like the “Human Capability Initiative” conference, scheduled for April 2025 in Riyadh. This major event, under the patronage of the Crown Prince, aims to prepare for future needs by focusing on developing human capabilities to adapt to rapid global changes. It will bring together over 300 global experts and leaders from various sectors to exchange ideas and promote readiness for the future job market. The Ministry of Education is also partnering in this effort, including hosting an educational exhibition. Additionally, King Abdulaziz University is organizing a conference on digital media and communication, and the Riyadh will host the Global Project Management Forum, all indicating a strong focus on development and innovation in line with Vision 2030.
5. What are the concerns and reactions regarding potential trade wars and tariffs, as discussed in the sources?
The sources express significant concern over the potential for escalating trade wars triggered by the United States imposing tariffs on imports, particularly from China. This has led to retaliatory tariffs and fears of a global economic slowdown or recession. International organizations like the United Nations Conference on Trade and Development (UNCTAD) have voiced concerns about the negative impact on poorer nations. The European Union is also considering a unified response to US tariffs, fearing a broader trade conflict that could harm global economies and consumers. Economic experts predict potential price increases for consumers and disruptions to international trade. The historical context of past tariffs and their impacts, such as during the Great Depression, is also referenced, highlighting the potential dangers of protectionist trade policies.
6. What is the situation in Gaza concerning humanitarian aid, water resources, and the impact of ongoing conflict on civilians, especially children?
The situation in Gaza is dire, with severe restrictions on the entry of humanitarian aid, medical supplies, and food, ongoing for at least 35 days according to UNICEF. This has led to a critical lack of essential resources, including treatment for malnutrition in children, exacerbated by renewed Israeli military actions. The conflict has caused widespread displacement, with nearly 1.9 million people, including many children, repeatedly forced to flee amidst shelling, fear, and loss. Water infrastructure has been severely damaged, with the central desalination plant west of Gaza City impacted, leading to a heavy reliance on tanker trucks to distribute limited water supplies. The psychological impact on civilians, particularly children, is also significant. The UN and other organizations continue to call for an end to hostilities and unfettered access for humanitarian assistance.
7. What cultural and heritage-related events and initiatives are highlighted in the sources within Saudi Arabia?
The sources showcase a vibrant cultural scene in Saudi Arabia. The “Nights in the Love of Khaled Al-Faisal” event in Jeddah, part of the “Jeddah Season 2025,” celebrates the artistic and literary contributions of Prince Khaled Al-Faisal. Riyadh is hosting “Riyadh Art Week,” featuring over 45 galleries and artistic spaces, aiming to highlight the Kingdom’s contemporary art scene and its interaction with the global art world. The King Salman Global Academy for the Arabic Language is collaborating with Indiana University in the US to conduct a training program for Arabic language teachers, emphasizing the development of modern teaching methods. Additionally, the Abu Dhabi Arabic Language Centre announced a new index, “Arabic Language Strength Index,” to measure and track the Arab community’s connection with the Arabic language. The historical village of Saduq, near Riyadh, is presented as a living heritage site reflecting the region’s deep historical and cultural roots. The revival of the traditional Najdi war dance during Eid celebrations in Al-Salmiyah also underscores efforts to preserve and pass on cultural heritage.
8. What are some of the international political and diplomatic activities involving Saudi Arabia mentioned in the sources, beyond the Palestinian issue?
Beyond its consistent stance on Palestine, Saudi Arabia is portrayed as an active player in international diplomacy. The sources mention Saudi Arabia hosting American, Russian, and Ukrainian officials for talks, indicating its potential role as a mediator in global conflicts. This is seen as a reflection of Saudi Arabia’s growing capabilities and ambitions in international relations, particularly in conflict resolution. The Kingdom’s Vision 2030 is credited with enhancing Saudi Arabia’s political standing and its ability to influence international issues. The sources suggest a future where Saudi Arabia plays an increasingly significant role in international mediation, moving beyond its traditional role in a region often associated with conflict.
Israeli Actions in Lebanon, Syria, and Jerusalem
The sources discuss Israeli occupation forces in several contexts.
One source mentions an Israeli raid in southern Lebanon, where the Israeli army announced it targeted two operatives in “Hezbollah”. A statement from the Lebanese Ministry of Health reported that the final death toll from this raid rose to two, after one injured person in Zibqin died from their severe wounds. The Israeli military spokesperson stated that the two individuals were targeted while rebuilding “terrorist infrastructure belonging to Hezbollah” in the “engineering sector”.
Another source discusses the Al-Aqsa Mosque in Jerusalem, mentioning that “Jewish Talmudic groups” according to “Temple organizations” are advocating for the introduction and slaughter of a young goat inside the mosque as a “sacrifice to God on the Arab Passover every year”. This source also notes that these “Temple” groups have managed to perform some rituals inside Al-Aqsa in past years, while their attempts to conduct animal sacrifices have failed, as this is described as the only religious ritual they haven’t been able to carry out inside the mosque. The context here refers to “the occupation,” indicating the perspective of those who view Israel’s presence in Jerusalem as an occupation.
Furthermore, the sources report on Israeli military actions in other regions, including “Israeli attacks” in Syria and a potential future “Israel attack”. A strike in Sidon, southern Lebanon, is also mentioned, following the killing of a leader in the Izz al-Din al-Qassam Brigades, his daughter, and his grandson in an Israeli raid in Hama, Syria. This strike in Sidon is noted as the second instance targeting the capital’s suburbs since a ceasefire was established.
The sources also refer to a past ceasefire agreement that stipulated the withdrawal of “Hezbollah” to north of the Litani River and the dismantling of their military installations, in exchange for the withdrawal of the Israeli army from all Lebanese territories it entered during a previous war. This agreement was considered a victory for Lebanon, linked to previous international resolutions, including those related to disarming all non-state forces. The text explicitly mentions “the occupied Lebanese territories” in this context.
Additionally, one source indicates that “Israel authorities” have a responsibility under international humanitarian law to ensure the basic needs of the population in the Gaza Strip are met. This implies a degree of control or responsibility over the territory and its inhabitants, consistent with the concept of occupation, although the term itself is not used in this specific instance.
Al-Aqsa Mosque: Israeli-Palestinian Context and Temple Groups
The sources discuss the Al-Aqsa Mosque in Jerusalem in the context of the Israeli-Palestinian issue and actions by certain religious groups.
One source mentions the Al-Aqsa Mosque in Jerusalem while reporting on the Kingdom’s condemnation of the Israeli occupation forces targeting a UNRWA clinic in the Jabalia camp in the Gaza Strip. This indicates that the Al-Aqsa Mosque is located in a context where Israel’s presence is viewed as an occupation.
Another source reports on calls by the “Return to the Temple Mount” organization urging its supporters to start attempting to slaughter sacrifices, such as a goat or sheep, inside the Al-Aqsa Mosque or at its gates during the Jewish Passover. This call was directed at supporters in the Old City of occupied Jerusalem, with the intention of trying throughout the following week to present the sacrifice at the “appropriate time” according to their interpretation of the Torah.
Furthermore, the sources detail that “Jewish Talmudic groups,” as stated by “Temple” organizations, advocate for the introduction and slaughter of a young goat inside the Al-Aqsa Mosque every year as a “sacrifice to God on the Arab Passover”. These “Temple” groups have reportedly succeeded in performing some religious rituals inside Al-Aqsa in past years, such as blowing the horn and offering plant sacrifices. However, their attempts to conduct animal sacrifices inside the mosque have failed, and this is described as the only religious ritual they haven’t been able to carry out there. This discussion about the Al-Aqsa Mosque is framed within the context of the “occupation”.
Gaza: Humanitarian Crisis and Regional Conflict
The sources discuss the Gaza Strip primarily in the context of the humanitarian crisis and the ongoing Israeli-Palestinian conflict.
One source highlights the critical need for humanitarian aid to enter the Gaza Strip. UNICEF has thousands of life-saving aid parcels, intended mostly for Gaza, that are currently being stored. Edward Beigbeder, UNICEF Regional Director for the Middle East and North Africa, emphasized the urgency of allowing immediate aid access, stating that it is a legal obligation under international law, not merely a charitable act. He specifically called on Israeli authorities to ensure the basic needs of the Palestinian population in the Gaza Strip are met, in accordance with their responsibilities under international humanitarian law. This includes the legal duty to guarantee the provision of essential items like food and medicine for families to survive.
Furthermore, the Gaza Strip is mentioned as a central point of solidarity in the region’s conflicts. Houthi forces have announced the resumption of naval attacks in the Red Sea and the Arabian Sea in support of the “Palestinian people in Gaza” against what they identify as “Israeli ships”. Their stated goal is to continue these operations and prevent navigation until the “aggression” against Gaza ceases and the blockade is lifted. This group is described as being aligned with Iran. In response, the United States has reportedly restarted intensive air strikes on Houthi-controlled areas in Yemen after a pause.
Additionally, one of the sources mentions that the Kingdom condemned the actions of “Israeli occupation forces” for targeting a UNRWA clinic in the Jabalia camp within the Gaza Strip. This indicates a perspective that views Israel as the occupying power in Gaza and denounces military actions taken by Israeli forces there.
US Trade Tariffs and Global Economic Impact
The sources discuss trade tariffs primarily in the context of actions taken by the United States, particularly under the administration of Donald Trump, and the responses from other countries and economic observers.
Several sources highlight a mutual trade tariff war between the USA and the rest of the world, triggered by US actions. Economists have advised investors to exercise caution and re-evaluate their investment strategies amidst these increasing trade tensions. The market downturn has been partly attributed to China imposing retaliatory tariffs on the United States. In response to these developments, the US Treasury Secretary acknowledged that the stock market experienced a short-term decline due to the tariffs but did not believe they would be the sole cause of an economic recession.
One source notes that US trade tariffs have historically rarely yielded positive outcomes. It points out that Donald Trump’s recent implementation of tariffs was a departure from the United States’ long-standing promotion of free trade and globalization. Historically, the US has imposed tariffs, but these measures have often failed to achieve convincing results. Trump’s policies included rejecting multilateral trade agreements such as the World Trade Organization (WTO) and the North American Free Trade Agreement (NAFTA), which was renegotiated into USMCA. These actions reflect a unilateral “America First” approach. Trump’s motivations included bolstering American industries, particularly in rural and industrial areas that form his electoral base, and reducing the federal budget deficit.
The European Union (EU) has also discussed the implications of US tariffs and potential countermeasures. EU ministers aimed to present a unified response and indicated a readiness to implement retaliatory measures if negotiations with Washington to remove the tariffs were unsuccessful.
Regarding the impact on other regions, the sources specifically mention Saudi Arabia and other Gulf countries. While the direct impact of US tariffs might be limited due to exemptions for energy products, there could be indirect effects. A slowdown in the US economy, potentially caused by these trade tensions, could reduce global demand for oil and petrochemical products, affecting the revenues of Gulf oil-producing nations. A more significant concern for the Gulf region was the consideration by Trump’s team to devalue the US dollar, which could lead to a reshaping of the global financial system.
Overall, the sources portray the imposition of trade tariffs by the US as a significant shift in international trade policy, generating retaliatory actions from other major economies and causing concern among investors and economic policymakers globally.
Global Cultural Exchange Initiatives
The sources discuss several cultural exchange initiatives across different fields, including language, arts, and broader human development.
One significant cultural exchange initiative is the cooperation between the King Salman Global Academy for the Arabic Language and Indiana University in the United States. This is a project aimed at training Arabic language teachers for non-native speakers. The program focuses on developing the teachers’ educational capabilities through advanced teaching methods and enhancing the skills of their students. According to the Secretary-General of the academy, “this program comes as a completion of the efforts made in developing the skills of Arabic language teachers and learners for non-native speakers”. The initiative reflects the academy’s “keenness to exchange experiences with Indiana University to benefit from academic expertise and the best practices in teaching the Arabic language at the international level”. The program includes a “specialized training course on linguistic tests and a course specialized in training on the ‘Hamza’ test (an academic test)”, emphasizing the practical application of assessment tools.
Another prominent cultural exchange initiative is “Riyadh Art Week”. This event is described as a “platform that brings together various components of the artistic scene in the Kingdom and the world, thereby contributing to drawing the features of the future of art in the region”. It aims to foster “purposeful dialogues between local and international artistic communities”. The week encompasses various activities, including “conversations and workshops”, a “video art program” showcasing the works of both “Saudi and international artists”, and “carefully curated art exhibitions” that are accompanied by “discussion sessions and interactive workshops” on local and global artistic topics. Notably, “a number of prominent Saudi artists open the doors of their studios to visitors, providing a unique opportunity for direct interaction with their creative methods”. The themes explored during the event include “the role of art in inspiration, connection, and challenge”, and it delves into topics like “how human arts face global and emerging issues”.
The upcoming “Human Capability Initiative conference” in Riyadh, in partnership with the Ministry of Education and the international education exhibition (EDGEx), also has aspects of cultural exchange. This initiative is intended to “discuss the latest practices and major projects in various sectors” and serve as a “platform for exchanging opinions and visions about projects, with the aim of achieving greater success and enhancing human capabilities”. The target audience includes professionals from the government and private sectors, engineering and contracting companies, entrepreneurs, consultants, and youth office managers, suggesting a broad exchange of knowledge and expertise.
Additionally, the “Winter at Tantora” festival is mentioned as a “global event that brings different cultures together”, explicitly highlighting its role in cultural exchange.
These examples demonstrate diverse cultural exchange initiatives discussed in the sources, spanning from formal academic collaborations focused on language education to large-scale artistic events fostering dialogue and interaction between local and international artists, as well as broader forums for the exchange of ideas and practices in human development and festivals celebrating cultural diversity.
Main Headings
برعاية الملك.. تكريم الفائزات بجائزة الأميرة نورة للتميز النسائي Under the King’s patronage, winners of the Princess Noura Award for Women’s Excellence are honored.
السوق السعودي يواكب هبوط البورصـات العالميـة The Saudi market keeps pace with the decline of global stock markets.
التصدي للتحايل بربط التأشيرة بمدة برنامج العمرة Combating fraud by linking the visa to the duration of the Umrah program
لبنان: مقتل شخصين في غارة إسرائيلية Lebanon: Two killed in Israeli airstrike
طـــهـــران تـــعـــارض عــقــد مـــفـــاوضـــات مــبــاشــرة مـــع واشــنــطــن Tehran opposes direct negotiations with Washington
غزة: مليون طفل يواجهون شبح المجاعة Gaza: One million children face the specter of famine
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
The provided text serves as a foundational resource for linear algebra, starting with basic concepts like vectors, vector spaces, real numbers, and geometric interpretations of these ideas. It progresses to vector operations such as addition, subtraction, scalar multiplication, and the crucial concepts of linear combinations and spans. The material then introduces special vectors like zero and unit vectors, along with the notion of linear independence and dependence. Further topics include the dot product and its relation to vector length, followed by an introduction to matrices, their operations (addition, subtraction, scalar multiplication, and matrix multiplication), and special types of matrices. The text also explores determinants and their geometric significance before moving into more advanced topics like vector spaces, bases, projections, orthonormal bases achieved through the Gram-Schmidt process, and finally, matrix decomposition techniques.
Vector Norms, Distances, Vector Operations, and Matrix Fundamentals Study Guide
I. Key Concepts and Definitions:
A. Vectors: * Definition: A quantity having magnitude and direction, often represented as an ordered list of numbers (components or entries). * Representation: Column vectors are commonly used, enclosed in square brackets (e.g., [x, y]). * Dimensions: An $n$-dimensional vector has $n$ components and belongs to the vector space $\mathbb{R}^n$. * Equality: Two vectors are equal if and only if all their corresponding components are equal.
B. Scalars: * Definition: A quantity with only magnitude (a single number).
C. Vector Norms: * Definition: A function that assigns a non-negative length or size to each vector in a vector space. * Norm Two (Euclidean Norm or $L^2$ Norm): For a vector $v = [v_1, v_2, …, v_n]^T$, the norm two is $||v||_2 = \sqrt{v_1^2 + v_2^2 + … + v_n^2}$.
D. Euclidean Distance: * Definition: The straight-line distance between two points in Euclidean space. * Formula: The Euclidean distance between two vectors $a = [a_1, a_2, …, a_n]^T$ and $b = [b_1, b_2, …, b_n]^T$ is $d(a, b) = ||a – b||_2 = \sqrt{(a_1 – b_1)^2 + (a_2 – b_2)^2 + … + (a_n – b_n)^2}$. * Relationship to Norm: The Euclidean distance between two points is the norm of the vector connecting them.
E. Special Vectors: * Zero Vector: A vector where all components are zero, denoted by $\vec{0}$. * Unit Vector: A vector with a magnitude (norm) of one. * Standard Unit Vectors ($e_i$): Vectors with a single component equal to one and all other components equal to zero (e.g., in $\mathbb{R}^3$, $e_1 = [1, 0, 0]^T$, $e_2 = [0, 1, 0]^T$, $e_3 = [0, 0, 1]^T$). * Sparse Vector: A vector with many of its entries as zero.
F. Vector Operations: * Addition: Adding two vectors of the same dimension is done component-wise: $(a + b)_i = a_i + b_i$. * Subtraction: Subtracting two vectors of the same dimension is done component-wise: $(a – b)_i = a_i – b_i$. * Scalar Multiplication: Multiplying a vector by a scalar multiplies each component of the vector by that scalar: $(ca)_i = c \cdot a_i$.
G. Properties of Vector Addition: * Commutativity: $a + b = b + a$ * Associativity: $(a + b) + c = a + (b + c)$ * Identity Element: $a + \vec{0} = \vec{0} + a = a$ * Inverse Element: $a + (-a) = (-a) + a = \vec{0}$, where $-a$ is the vector with components $-a_i$.
H. Linear Combination: * Definition: A vector formed by multiplying a set of vectors by scalars and adding the results. For vectors $v_1, v_2, …, v_k$ and scalars $c_1, c_2, …, c_k$, the linear combination is $c_1v_1 + c_2v_2 + … + c_kv_k$. * Coefficients: The scalars ($c_i$) in a linear combination.
I. Span of Vectors: * Definition: The set of all possible linear combinations of a set of vectors. * Example: The span of two non-collinear vectors in $\mathbb{R}^2$ is the entire $\mathbb{R}^2$. The span of two collinear vectors in $\mathbb{R}^2$ is a line through the origin. The span of a single non-zero vector in $\mathbb{R}^2$ is a line through the origin. The span of the zero vector is just the zero vector.
J. Dot Product (Scalar Product): * Definition: An operation that takes two equal-length sequences of numbers (usually coordinate vectors) and returns a single number. * Formula: For two vectors $a = [a_1, a_2, …, a_n]^T$ and $b = [b_1, b_2, …, b_n]^T$, their dot product is $a \cdot b = a_1b_1 + a_2b_2 + … + a_nb_n$. * Relationship to Norm: $v \cdot v = ||v||_2^2$.
K. Matrices: * Definition: A rectangular array of numbers arranged in rows and columns. * Dimensions: An $m \times n$ matrix has $m$ rows and $n$ columns. * Indexing: The element in the $i$-th row and $j$-th column is denoted as $A_{ij}$ or $a_{ij}$. * Square Matrix: A matrix with an equal number of rows and columns ($m = n$). * Identity Matrix ($I_n$): An $n \times n$ square matrix with ones on the main diagonal (from the upper-left to the lower-right) and zeros everywhere else. * Matrix Equality: Two matrices are equal if and only if they have the same dimensions and all their corresponding entries are equal.
L. Matrix Operations: * Scalar Multiplication: Multiplying a matrix by a scalar multiplies each entry of the matrix by that scalar. * Matrix Addition and Subtraction: Performed element-wise on matrices of the same dimensions. * Matrix Multiplication: The product of an $m \times k$ matrix $A$ and a $k \times n$ matrix $B$ is an $m \times n$ matrix $C$, where $C_{ij} = \sum_{l=1}^{k} A_{il}B_{lj}$ (the dot product of the $i$-th row of $A$ and the $j$-th column of $B$).
M. Properties of Matrix Operations: * Associativity of Matrix Multiplication: $(AB)C = A(BC)$ * Distributivity: $A(B + C) = AB + AC$ and $(A + B)C = AC + BC$ * Scalar Multiplication with Matrix Multiplication: $r(AB) = (rA)B = A(rB)$ * Identity Matrix Property: $AI = IA = A$, where $I$ is the identity matrix of appropriate dimension.
N. Determinants: * Definition (for a $2 \times 2$ matrix): For a matrix $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, the determinant is $\det(A) = ad – bc$. * Calculation (by cofactor expansion): The determinant of a matrix can be calculated by expanding along any row or column using cofactors. * Properties: * $\det(I) = 1$ * Swapping two rows (or columns) changes the sign of the determinant. * If a matrix has a row (or column) of zeros, its determinant is zero. * If a matrix has two identical rows (or columns), its determinant is zero. * Multiplying a row (or column) by a scalar $c$ multiplies the determinant by $c$. * $\det(A^T) = \det(A)$ * $\det(AB) = \det(A)\det(B)$
O. Basis of a Vector Space: * Definition: A set of linearly independent vectors that span the entire vector space. * Properties: Every vector in the space can be expressed as a unique linear combination of the basis vectors.
P. Orthonormal Basis: * Definition: A basis where all vectors in the set are orthogonal to each other and each vector has a norm (length) of one (they are unit vectors). * Orthogonal Vectors: Two vectors $u$ and $v$ are orthogonal if their dot product is zero ($u \cdot v = 0$). * Gram-Schmidt Process: An algorithm for orthonormalizing a set of linearly independent vectors in an inner product space.
II. Quiz:
Explain the relationship between the Euclidean norm of a vector and the Euclidean distance between two points.
What are the key differences between a zero vector and a unit vector? Provide an example of each in $\mathbb{R}^3$.
Describe the process of adding two vectors and multiplying a vector by a scalar. How do the dimensions of the vectors play a role?
State the commutative and associative properties of vector addition. Provide a brief example to illustrate one of these properties.
Define a linear combination of vectors. What role do the coefficients in a linear combination play?
Explain the concept of the span of a set of vectors. What does it mean if the span of a set of vectors in $\mathbb{R}^n$ is equal to $\mathbb{R}^n$?
What is the formula for the dot product of two $n$-dimensional vectors? How is the dot product related to the norm of a vector?
Describe the structure of an $n \times n$ identity matrix. How does it behave when multiplied by another matrix?
For a $2 \times 2$ matrix $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, what is its determinant? How does swapping the rows of $A$ affect its determinant?
Define a basis of a vector space. What two key properties must a set of vectors satisfy to form a basis?
III. Quiz Answer Key:
The Euclidean distance between two points (represented by vectors $a$ and $b$) is defined as the Euclidean norm of the vector that connects these two points, which is the vector $a – b$ (or $b – a$). Thus, $d(a, b) = ||a – b||_2$.
A zero vector is a vector where all its components are zero (e.g., $[0, 0, 0]^T$ in $\mathbb{R}^3$), and its magnitude is zero. A unit vector is a vector whose Euclidean norm (length) is one (e.g., $[1, 0, 0]^T$ in $\mathbb{R}^3$).
To add two vectors, their corresponding components are added together. To multiply a vector by a scalar, each component of the vector is multiplied by that scalar. Vector addition is only defined for vectors of the same dimension, and the resulting vector has the same dimension.
The commutative property states that the order of addition does not matter: $a + b = b + a$. For example, if $a = [1, 2]^T$ and $b = [3, 4]^T$, then $a + b = [4, 6]^T$ and $b + a = [4, 6]^T$.
A linear combination of vectors $v_1, v_2, …, v_k$ is a sum of scalar multiples of these vectors: $c_1v_1 + c_2v_2 + … + c_kv_k$. The coefficients ($c_i$) determine how each vector is scaled and contribute to the resulting vector of the combination.
The span of a set of vectors is the set of all vectors that can be formed by taking linear combinations of the original vectors. If the span of a set of vectors in $\mathbb{R}^n$ is equal to $\mathbb{R}^n$, it means that any vector in the $n$-dimensional space can be expressed as a linear combination of the vectors in that set.
The dot product of two $n$-dimensional vectors $a = [a_1, …, a_n]^T$ and $b = [b_1, …, b_n]^T$ is $a \cdot b = a_1b_1 + … + a_nb_n$. The dot product of a vector with itself is equal to the square of its Euclidean norm: $v \cdot v = ||v||_2^2$.
An $n \times n$ identity matrix ($I_n$) is a square matrix with ones on its main diagonal and zeros elsewhere. When an $m \times n$ matrix $A$ is multiplied by an $n \times n$ identity matrix $I_n$, the result is $A$. Similarly, when an $n \times n$ identity matrix $I_n$ is multiplied by an $n \times k$ matrix $B$, the result is $B$.
For $A = \begin{pmatrix} a & b \ c & d \end{pmatrix}$, $\det(A) = ad – bc$. Swapping the rows of $A$ results in the matrix $\begin{pmatrix} c & d \ a & b \end{pmatrix}$, whose determinant is $cb – da = -(ad – bc) = -\det(A)$. Thus, swapping rows changes the sign of the determinant.
A basis of a vector space is a set of vectors that satisfies two key properties: (1) the vectors in the set must be linearly independent (no vector in the set can be expressed as a linear combination of the others), and (2) the vectors in the set must span the entire vector space (every vector in the space can be expressed as a linear combination of the basis vectors).
IV. Essay Format Questions:
Discuss the significance of vector norms and Euclidean distance in various fields such as machine learning and data analysis. Provide specific examples of how these concepts are applied.
Explain the concept of linear dependence and linear independence of vectors. How is this concept related to the idea of a basis for a vector space and the uniqueness of linear combinations?
Describe the process of matrix multiplication and its properties. Compare and contrast matrix multiplication with scalar multiplication and discuss the implications of the non-commutative nature of matrix multiplication.
Explain the concept of the determinant of a square matrix and its key properties. Discuss the geometric interpretation of the determinant in two and three dimensions.
Describe the Gram-Schmidt process for orthonormalizing a set of linearly independent vectors. Explain the importance of orthonormal bases in linear algebra and its applications.
V. Glossary of Key Terms:
Vector: A quantity with both magnitude and direction, represented as an ordered list of numbers.
Scalar: A quantity with only magnitude (a single number).
Norm: A function that assigns a non-negative length or size to a vector.
Euclidean Norm ($L^2$ Norm): The square root of the sum of the squares of the vector’s components, representing its length.
Euclidean Distance: The straight-line distance between two points in Euclidean space.
Zero Vector: A vector with all components equal to zero.
Unit Vector: A vector with a magnitude (norm) of one.
Standard Unit Vectors: Vectors with one component equal to one and all others zero.
Sparse Vector: A vector with many zero entries.
Linear Combination: A vector formed by a sum of scalar multiples of other vectors.
Span: The set of all possible linear combinations of a set of vectors.
Dot Product: An operation on two vectors that returns a scalar, calculated as the sum of the products of their corresponding components.
Matrix: A rectangular array of numbers arranged in rows and columns.
Square Matrix: A matrix with an equal number of rows and columns.
Identity Matrix: A square matrix with ones on the main diagonal and zeros elsewhere.
Determinant: A scalar value that can be computed from the elements of a square matrix, providing information about the matrix’s properties.
Basis: A set of linearly independent vectors that span the entire vector space.
Orthonormal Basis: A basis where all vectors are orthogonal (dot product is zero) and have a norm of one.
Orthogonal Vectors: Two vectors whose dot product is zero.
Gram-Schmidt Process: An algorithm for orthonormalizing a set of linearly independent vectors.
Briefing Document: Review of Linear Algebra Concepts
This briefing document summarizes the main themes and important ideas from the provided source material, focusing on foundational concepts in linear algebra, including vectors, norms, distance, matrices, determinants, linear transformations, and the Gram-Schmidt process.
I. Vectors: Fundamental Building Blocks
Definition and Representation: Vectors are quantities possessing both magnitude (length) and direction, distinguishing them from scalars, which only have magnitude. They can be represented geometrically as arrows in space or algebraically as ordered lists of numbers (components or entries).
In a two-dimensional space (R²), a vector can be represented as [x, y] or using parentheses like (4, 0) or {3, 4}. The components indicate the movement along the horizontal (x) and vertical (y) axes.
In an n-dimensional space (Rⁿ), a vector a is represented as a column of n elements:
[ A₁ ]
[ A₂ ]
[ … ]
[ A<0xE2><0x82><0x99> ]
The index of a vector’s element starts from 1 to n. Notation like Aᵢ refers to the i-th element of vector A.
Vectors can also contain other vectors as entries (nested vectors), which can be represented using capital letters (e.g., A) with arrow notation for the vector entries (e.g., A₁). In such cases, double indexing (e.g., a₁₁) is used to denote the element within a specific vector entry.
Magnitude (Norm) and Distance:
The norm of a vector measures its size or length. For a vector v = [v₁, v₂, …, v<0xE2><0x82><0x99>], the norm (specifically the L₂ norm or Euclidean norm) is calculated as:
||v|| = √(v₁² + v₂² + … + v<0xE2><0x82><0x99>²)
“take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector”. For example, the norm of vector v = [3, 4] is √(3² + 4²) = √25 = 5.
The Euclidean distance (also called L₂ distance or “aladine distance” in the source) between two points (vectors) A and B in n-dimensional space is the norm of the vector connecting A to B (B – A or A – B).
“the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B”. The order of subtraction inside the square doesn’t matter due to the squaring operation.
Special Vectors:
Zero Vector: A vector where all its components are zero. Denoted as 0 with an arrow on top (e.g., 0 in R³ is [0, 0, 0]). “the zero and arrow on the top it basically refers to the vector like we saw before only with the difference that all its me numbers are zero”.
Unit Vectors: Vectors with one element equal to one and all others zero. The i-th unit vector in n dimensions, eᵢ, has a 1 in the i-th position and 0 elsewhere (e.g., in R³, e₁ = [1, 0, 0], e₂ = [0, 1, 0], e₃ = [0, 0, 1]). “vectors with a single element equal to one and all the others zero denoted as EI for the E unit Vector in N dimensions are referred by unit vectors”.
Sparse Vectors: Vectors with many of their entries as zero.
Vector Operations:
Addition: Two vectors of the same dimension are added element-wise. “when it comes to Vector addition we just add the corresponding elements”.
Subtraction: Similar to addition, subtraction is performed element-wise.
Scalar Multiplication: Multiplying a vector by a scalar involves multiplying each component of the vector by that scalar, effectively scaling the vector’s magnitude. “formally the scalar multiplication involves multiplying each component of a vector by scalar value effectively scaling the vector’s magnitude”.
Properties of Vector Addition:
Commutative: a + b = b + a. “adding two different VOR the direction or the order is not important”.
Associative: (a + b) + c = a + (b + c).
Identity Element: There exists a zero vector 0 such that a + 0 = a. “adding a zero Vector to this original a vector or not we in all cases it just adding a zero Vector has no effect”.
Inverse Element: For every vector a, there exists a vector -a such that a + (-a) = 0. Subtracting a vector from itself results in the zero vector. “when we have a vector consisting of the scalers like a is equal 2 23 in the same manner if we take this a and we subtract it from itself so a minus a then what we will get is … Vector zero”.
Applications of Vectors:
Word Counting: Vectors can represent the frequency of words in a document. Each element of the vector corresponds to a word in a dictionary, and the value represents the number of times that word appears. This is fundamental in natural language processing for tasks like topic modeling and sentiment analysis. “a vector of a length n for instance can represent the number of times each of these words in a dictionary of n words appears in a document”.
Customer Purchases: Vectors can record customer purchases over time, with each element representing the quantity or dollar value of a specific item purchased.
II. Span and Linear Combinations
Linear Combination: A linear combination of vectors A₁, A₂, …, A<0xE2><0x82><0x99> is an expression of the form β₁A₁ + β₂A₂ + … + β<0xE2><0x82><0x99>A<0xE2><0x82><0x99>, where β₁, β₂, …, β<0xE2><0x82><0x99> are scalar coefficients. “a linear combination simply involves taking several vectors … and to get a linear combination we need to uh scale each of those vectors which means that we need to have these different scalers”. The scalars are the “coefficients of linear combination”.
Span: The span of a set of vectors is the set of all possible vectors that can be formed by taking all possible linear combinations of those vectors. “the spend of a set of vectors is a set of all possible linear combinations of these vectors”.
Relationship between Span and Linear Combination: If a vector b can be expressed as a linear combination of vectors in a set V, then b lies within the span of V.
Span Examples:The span of the zero vector is just the zero vector itself.
The span of a single non-zero vector in R² or R³ is the line passing through the origin and the vector.
The span of two non-parallel vectors in R² is the entire R² plane. If they are parallel, their span is a line.
Any vector in Rⁿ can be expressed as a linear combination of the standard unit vectors e₁, e₂, …, e<0xE2><0x82><0x99>. The coefficients of this linear combination are simply the components of the vector itself. “any Vector B in N Dimensions can be expressed as a linear combination of a standard unit vectors E1 up to e n … those coefficients they are not just randomly picked coefficients those are the entries of this Vector B”.
III. Matrices: Arrays of Numbers
Definition and Representation: A matrix is a rectangular array of numbers arranged in rows and columns. An m x n matrix has m rows and n columns. Elements of a matrix A are denoted by aᵢⱼ, where i is the row index and j is the column index (starting from 1). “a matrix is nothing else than a rectangular array of numbers organized in rows and columns”.
Special Types of Matrices:
Identity Matrix (I<0xE2><0x82><0x99>): A square (n x n) matrix with ones on the main diagonal (from top-left to bottom-right) and zeros elsewhere. It is formed by combining the unit vectors as its columns (or rows). “the identity Matrix i n which is a square Matrix with one on the diagonal and zeros elsewhere is basically a matrix that is built using those unit vectors”. The determinant of an identity matrix is always 1.
Zero Matrix: A matrix where all its elements are zero.
Square Matrix: A matrix with an equal number of rows and columns (n x n).
Diagonal Matrix: A square matrix where all the off-diagonal elements are zero. The identity matrix is a special case of a diagonal matrix.
Matrix Operations:
Scalar Multiplication: Multiplying a matrix by a scalar involves multiplying every element of the matrix by that scalar.
Matrix Addition and Subtraction: Performed element-wise between matrices of the same dimensions.
Matrix Multiplication: The product of an m x p matrix A and a p x n matrix B is an m x n matrix C, where each element cᵢⱼ is the dot product of the i-th row of A and the j-th column of B. Matrix multiplication is generally not commutative (AB ≠ BA).
Properties of Matrix Operations: Scalar multiplication distributes over matrix addition, and matrix multiplication is associative and distributes over matrix addition. r(AB) = (rA)B = A(rB).
IV. Determinants: A Scalar Value of a Square Matrix
Definition and Importance: The determinant is a scalar value that can be computed from the elements of a square matrix. It provides important information about the matrix, such as whether the matrix is invertible and the volume scaling factor of the linear transformation represented by the matrix. “the determinant is a scalar value that can be computed from the elements of a square Matrix”.
Calculation:2×2 Matrix: For a matrix [[a, b], [c, d]], the determinant is ad – bc.
3×3 Matrix: Can be calculated using the rule of Sarrus or by cofactor expansion along any row or column. The formula involves sums and differences of products of three elements, with signs determined by the position of the elements.
General (n x n) Matrix: Calculated using cofactor expansion recursively. The determinant is the sum (or difference) of the products of each element in a row (or column) with its corresponding cofactor, which is (-1)^(i+j) times the determinant of the submatrix obtained by removing the i-th row and j-th column.
Properties of Determinants:The determinant of the identity matrix is 1.
Swapping two rows or columns of a matrix changes the sign of its determinant.
If a matrix has a row or a column of zeros, its determinant is zero.
If a matrix has two identical rows or columns, its determinant is zero.
Multiplying a row or column of a matrix by a scalar k multiplies the determinant by k.
The determinant of a triangular matrix (upper or lower) is the product of its diagonal elements.
The determinant of the transpose of a matrix is equal to the determinant of the original matrix: det(Aᵀ) = det(A).
The determinant of a product of matrices is the product of their determinants: det(AB) = det(A) det(B).
V. Basis of a Vector Space
Definition: A basis of a vector space is a set of linearly independent vectors that span the entire vector space. Every vector in the space can be expressed as a unique linear combination of the basis vectors. “a basis of a vector space is a set of all both linearly independent vectors that spend the entire Vector space”.
Linearly Independent Vectors: A set of vectors is linearly independent if no vector in the set can be written as a linear combination of the others.
Spanning the Entire Vector Space: A set of vectors spans a vector space if every vector in the space can be expressed as a linear combination of the vectors in the set.
VI. Gram-Schmidt Process: Orthonormalizing a Set of Vectors
Purpose: The Gram-Schmidt process is an algorithm for orthonormalizing a set of linearly independent vectors in an inner product space (like Euclidean space). The output is a set of orthonormal vectors that span the same subspace as the original set.
Orthonormal Vectors: A set of vectors is orthonormal if all vectors in the set are orthogonal (their dot product is zero) and each vector has a norm (length) of 1.
Steps:Start with a set of linearly independent vectors {a₁, a₂, …, a<0xE2><0x82><0x99>}.
The first orthogonal vector v₁ is the same as the first original vector: v₁ = a₁. The first orthonormal vector e₁ is obtained by normalizing v₁: e₁ = v₁ / ||v₁||.
For each subsequent vector a<0xE2><0x82><0x99> (where k > 1), the orthogonal vector v<0xE2><0x82><0x99> is obtained by subtracting its projection onto the previously computed orthonormal vectors:
“we need to subtract is projection on all previously computed orthogonal vectors by using this formula”.
The orthonormal vector e<0xE2><0x82><0x99> is then obtained by normalizing v<0xE2><0x82><0x99>: e<0xE2><0x82><0x99> = v<0xE2><0x82><0x99> / ||v<0xE2><0x82><0x99>||.
Repeat steps 3 and 4 for all vectors in the original set.
This briefing document provides a foundational overview of key linear algebra concepts discussed in the provided source material. Understanding these concepts is crucial for various applications in machine learning, data science, and other quantitative fields.
Frequently Asked Questions on Linear Algebra Concepts
1. What is the Euclidean distance and how is it related to the norm of a vector? The Euclidean distance between two points, say A and B, in an N-dimensional space is a measure of the straight-line distance between them. Mathematically, if A has coordinates (A1, A2, …, An) and B has coordinates (B1, B2, …, Bn), the Euclidean distance d(A, B) is calculated as the square root of the sum of the squares of the differences between their corresponding coordinates: √((A1 – B1)² + (A2 – B2)² + … + (An – Bn)²).
The norm of a vector, on the other hand, measures the length or magnitude of a single vector. For a vector V with components (V1, V2, …, Vn), the L2 norm (also known as the Euclidean norm or just the norm) is defined as ||V||₂ = √(V1² + V2² + … + Vn²).
The Euclidean distance between two points A and B can be seen as the norm of the vector that connects A to B. If we form a vector by subtracting the coordinates of A from B (or vice versa), the norm of this resulting vector is equal to the Euclidean distance between A and B. For example, if the vector connecting A to B is V = B – A = (B1 – A1, B2 – A2, …, Bn – An), then the norm of V, ||V||₂, is exactly the Euclidean distance d(A, B). Thus, the Euclidean distance is a specific application of the norm concept, applied to the vector representing the displacement between two points.
2. How are vectors represented, and what distinguishes them from scalars? Vectors are quantities that possess both magnitude (length) and direction. They are typically represented in a coordinate system. In a two-dimensional space (R²), a vector can be represented by its x and y components, either in parentheses (e.g., (4, 0)) or in square braces (e.g., [3, 4]). In a three-dimensional space (R³), a vector is represented by its x, y, and z components (e.g., (a, b, c) or [a, b, c]). Generally, in an N-dimensional space (Rⁿ), a vector ‘a’ can be represented as a column vector with n entries: [A1, A2, …, An]ᵀ.
Scalars, in contrast, are quantities that have only magnitude and no direction. They are simply numbers (real numbers in the context of these sources). Examples of scalars include temperature, speed (as opposed to velocity), and mass.
The key distinction is the presence of direction. Vectors describe a movement or displacement from one point to another in space, characterized by how far to move in each dimension, while scalars just indicate an amount or quantity.
3. What are zero vectors and unit vectors, and why are they important? A zero vector is a vector in which all of its components are zero (e.g., [0, 0, 0] in R³). It has zero magnitude and no specific direction. Zero vectors are important because they act as the additive identity in vector addition (adding a zero vector to any vector does not change the vector). They are also useful in various linear algebra operations and algorithms, such as representing a null displacement or an initial state.
Unit vectors are vectors with a magnitude (length) of one. In N dimensions, the standard unit vectors, often denoted as eᵢ, have a single component equal to one at the i-th position and all other components equal to zero (e.g., e₁ = [1, 0, 0]ᵀ, e₂ = [0, 1, 0]ᵀ, e₃ = [0, 0, 1]ᵀ in R³). Unit vectors are crucial because they provide a standard basis for representing any vector in a vector space as a linear combination of these unit vectors. They are also used to indicate direction without magnitude and are essential in concepts like vector normalization and coordinate systems.
4. What does the sparsity of a vector refer to, and why is it significant? The sparsity of a vector refers to the characteristic of having many of its entries as zero. A sparse vector is one where a significant proportion of its components are zero. The sparsity pattern indicates the positions of the non-zero entries.
Sparsity is significant for several reasons, especially in high-dimensional data and computations.
Computational Efficiency: Operations involving sparse vectors (like dot products or matrix-vector multiplications) can be performed more efficiently as we only need to process the non-zero elements. This saves time and memory.
Data Representation: In many real-world applications, data can be naturally sparse. For example, in text analysis, a document can be represented as a vector where each component corresponds to a word in a vocabulary, and most components will be zero for words that do not appear in that document.
Feature Selection: Sparsity is often a desirable property in machine learning models, as it can lead to feature selection (where irrelevant features have zero weights), making the models simpler, more interpretable, and less prone to overfitting.
5. How are vectors used to represent word counts in a document? Vectors can be used to represent the frequency of words in a document by creating a vector where each dimension corresponds to a unique word in a predefined vocabulary (or dictionary). The value in each dimension of the vector represents the number of times that specific word appears in the document.
For example, if our dictionary consists of the words {“word”, “row”, “number”, “horse”, “eel”, “document”}, a document could be represented by the vector [3, 2, 1, 0, 4, 2]. This vector indicates that the word “word” appears 3 times, “row” appears 2 times, “number” appears 1 time, “horse” appears 0 times, “eel” appears 4 times, and “document” appears 2 times in the document.
This representation is fundamental in natural language processing for tasks like text analysis, information retrieval, and building language models. By quantifying word occurrences, we can perform mathematical operations on text data, such as comparing documents based on their word content or identifying the topic of a document. The concept of stop words (common words like “the”, “is”, “a”) which often have high frequencies but low informational value, is also relevant in this context.
6. Explain the operations of vector addition and subtraction. Vector addition is performed element-wise. If we have two vectors, say A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and B = [B₁, B₂, …, B<0xE2><0x82><0x99>]ᵀ, both in Rⁿ, their sum C = A + B is a new vector C = [A₁ + B₁, A₂ + B₂, …, A<0xE2><0x82><0x99> + B<0xE2><0x82><0x99>]ᵀ. This means that the i-th component of the resulting vector is the sum of the i-th components of the two original vectors. Vector addition requires that the vectors have the same dimensions.
Similarly, vector subtraction is also performed element-wise. If we have two vectors A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and B = [B₁, B₂, …, B<0xE2><0x82><0x99>]ᵀ, their difference D = A – B is a vector D = [A₁ – B₁, A₂ – B₂, …, A<0xE2><0x82><0x99> – B<0xE2><0x82><0x99>]ᵀ. The i-th component of the resulting vector is the difference between the i-th components of the two original vectors. Like addition, vector subtraction also requires the vectors to have the same dimensions.
Geometrically, vector addition can be visualized using the parallelogram law or the head-to-tail method, where the resultant vector represents the diagonal of the parallelogram formed by the two vectors or the vector from the tail of the first to the head of the second. Vector subtraction A – B can be thought of as adding A to the vector -B, where -B has the same magnitude as B but points in the opposite direction.
7. What are the key properties of vector addition? Vector addition satisfies several important properties:
Commutativity: The order of addition does not matter. For any two vectors A and B, A + B = B + A. This is because scalar addition of their corresponding components is commutative.
Associativity: When adding three or more vectors, the way they are grouped does not affect the result. For any three vectors A, B, and C, (A + B) + C = A + (B + C). This follows from the associativity of scalar addition.
Identity Element: There exists a zero vector (0) such that for any vector A, A + 0 = 0 + A = A. The zero vector acts as the additive identity.
Inverse Element: For every vector A, there exists an additive inverse, denoted as -A, such that A + (-A) = (-A) + A = 0 (the zero vector). The inverse -A is obtained by negating each component of A.
These properties make the set of all vectors in a vector space under the operation of vector addition an abelian group, which is a fundamental concept in linear algebra.
8. Explain scalar multiplication of a vector and the concept of a linear combination of vectors. Scalar multiplication involves multiplying a vector by a scalar (a number). If we have a vector A = [A₁, A₂, …, A<0xE2><0x82><0x99>]ᵀ and a scalar c, the scalar product cA is a new vector where each component of A is multiplied by c: cA = [cA₁, cA₂, …, cA<0xE2><0x82><0x99>]ᵀ. Scalar multiplication effectively scales the magnitude (length) of the vector by |c|. If c is negative, it also reverses the direction of the vector.
A linear combination of a set of vectors {A₁, A₂, …, A<0xE2><0x82><0x99>} is a vector that is obtained by multiplying each vector in the set by a scalar and then adding the results together. If c₁, c₂, …, c<0xE2><0x82><0x99> are scalars, then a linear combination of these vectors is given by: L = c₁A₁ + c₂A₂ + … + c<0xE2><0x82><0x99>A<0xE2><0x82><0x99>. The scalars c₁, c₂, …, c<0xE2><0x82><0x99> are called the coefficients of the linear combination. Linear combinations are fundamental to understanding concepts like span, basis, and linear independence in vector spaces. Any vector in a vector space can often be expressed as a linear combination of a set of basis vectors for that space.
Understanding Linear Combinations of Vectors
A linear combination of vectors A₁ up to A<0xE2><0x82><0x98> using scalars β₁ up to β<0xE2><0x82><0x98> (also referred to as coefficients) is a vector formed by multiplying each vector by its corresponding scalar and then adding the results. Formally, it is expressed as β₁ * A₁ + β₂ * A₂ + … + β<0xE2><0x82><0x98> * A<0xE2><0x82><0x98>. The scalars β₁, β₂, …, β<0xE2><0x82><0x98> are real numbers.
Here’s a breakdown of the key concepts:
Vectors: A linear combination involves a set of vectors, for example, A₁, A₂, up to A<0xE2><0x82><0x98>.
Scalars (Coefficients): Each vector in the set is multiplied by a scalar, such as β₁, β₂, up to β<0xE2><0x82><0x98>. These scalars are real numbers. The choice of these coefficients determines the resulting linear combination.
Scalar Multiplication: Multiplying a vector by a scalar scales the vector’s magnitude. If the scalar is negative, it also reverses the vector’s direction.
Vector Addition: The scaled vectors are then added together element-wise to produce the linear combination. The resulting vector has the same size as the original vectors being combined.
Examples of Linear Combinations:
Let’s consider two vectors A = and B =. Some linear combinations of A and B are:
The coefficients (β₁, β₂, …, β<0xE2><0x82><0x98>) are crucial because they define how the vectors are combined. By choosing different sets of coefficients, we can obtain different linear combinations of the same set of vectors. Finding these coefficients is often the goal in many applications of linear algebra.
Linear Combination of Unit Vectors:
Any vector B in an N-dimensional space (Rⁿ) can be expressed as a linear combination of the standard unit vectors E₁ up to E<0xE2><0x82><0x99>. The coefficients in this linear combination are the entries of the vector B itself.
For example, in three-dimensional space (R³), a vector B = [-1, 3, 5] can be written as a linear combination of the unit vectors E₁ =, E₂ =, and E₃ = as follows:
The span of a set of vectors is defined as the set of all possible linear combinations of those vectors. For instance, if the span of vectors A and B is R², it means that any vector in the two-dimensional plane can be expressed as a linear combination of A and B.
In the example with A = and B =, it was shown that any vector X = [X₁, X₂] in R² could be represented as a linear combination of A and B by finding appropriate coefficients β₁ and β₂. This demonstrates that the span of A and B is R².
However, if two vectors are linearly dependent (one can be written as a scalar multiple of the other), their span will be a line rather than the entire R². For example, if A = and B = (where B = 3A), their linear combinations will always lie on the same line.
Linear combinations are a fundamental concept in linear algebra, providing a way to understand how vectors can be combined to generate other vectors and define vector spaces and their properties like span and linear independence.
Understanding the Span of Vector Sets
The span of a set of vectors is the set of all possible linear combinations of those vectors. If you have a set of vectors, say V = {V₁, V₂, …, V<0xE2><0x82><0x98>}, then the span of V, often written as span(V), encompasses every vector that can be created by taking a linear combination of V₁, V₂, …, V<0xE2><0x82><0x98>. This means any vector in span(V) can be expressed in the form c₁V₁ + c₂V₂ + … + c<0xE2><0x82><0x98>V<0xE2><0x82><0x98>, where c₁, c₂, …, c<0xE2><0x82><0x98> are any real numbers (scalars).
We can explore the span of vectors through several cases, as discussed in the sources:
Span of the Zero Vector: If you have a set containing only the zero vector (e.g., a = ), then any linear combination of this vector will always result in the zero vector (c * = ). Therefore, the span of the zero vector is just the zero vector itself.
Span of a Single Non-Zero Vector: Consider a single non-zero vector, for example, a =. The span of this vector consists of all its scalar multiples (c * = [c, 2c]). When visualized in R², these scalar multiples will all lie on the same line passing through the origin and in the direction of the vector a. Thus, the span of a single non-zero vector in R² is a line passing through the origin. You can move along this line by choosing different scalar values for ‘c’, but you cannot reach any point off this line.
Span of Two Perpendicular Vectors: Let’s take two perpendicular vectors in R², such as a = and b =. The span of these two vectors is the set of all linear combinations of the form c₁a + c₂b = c₁ + c₂ = [c₁, c₂]. Since c₁ and c₂ can be any real numbers, this linear combination can produce any vector in R². Therefore, the span of two perpendicular vectors like and (which are the standard unit vectors E₁ and E₂) is the entire R². Any point in the 2D plane can be reached by some combination of these two vectors.
Span of Two Vectors Where the Span is R²: Consider two vectors V₁ = and V₂ =. It can be shown that the span of these two vectors is also R². This means that any vector X = [X₁, X₂] in R² can be expressed as a linear combination of V₁ and V₂ (C₁V₁ + C₂V₂ = X) by finding appropriate coefficients C₁ and C₂. This was demonstrated in the source by solving for C₁ and C₂ in terms of X₁ and X₂.
Span of Linearly Dependent Vectors: As mentioned in our previous conversation and implicitly in the source, if two vectors are linearly dependent (one is a scalar multiple of the other, like a = and b = where b = 3a), their span will be a line through the origin. All linear combinations of these vectors will lie on the same line because essentially, you are only varying the magnitude (and possibly direction) along a single direction.
In summary, the span of a set of vectors defines the subspace that can be reached by taking all possible linear combinations of those vectors. The number of vectors and their linear independence play a crucial role in determining the nature of the span (e.g., a point, a line, a plane, or the entire vector space). If the span of a set of vectors is the entire vector space, then that set of vectors is said to span the vector space. This concept is closely linked to linear independence and the basis of a vector space. A basis is a set of linearly independent vectors that span the entire vector space.
Linear Independence in Vector Spaces
Linear independence of a set of vectors is a fundamental concept in linear algebra that describes whether any vector in the set can be expressed as a linear combination of the others. Conversely, if at least one vector in the set can be written as a linear combination of the remaining vectors, then the set is said to be linearly dependent.
Formally, a set of vectors {V₁, V₂, …, V<0xE2><0x82><0x98>} is linearly independent if and only if the only solution to the vector equation:
is the trivial solution, where all the scalars (coefficients) c₁, c₂, …, c<0xE2><0x82><0x98> are equal to zero. In other words, the only way to get a linear combination of these vectors to equal the zero vector is by setting all the coefficients to zero.
If there exists a set of scalars c₁, c₂, …, c<0xE2><0x82><0x98>, where at least one of them is non-zero, such that the linear combination equals the zero vector, then the vectors {V₁, V₂, …, V<0xE2><0x82><0x98>} are linearly dependent. In this case, the non-zero coefficients indicate that at least one vector in the set can be expressed as a linear combination of the others.
Examples of Linear Dependence:
Consider two vectors a = and b =. We can see that b is a scalar multiple of a (b = 3a). Therefore, we can write the linear combination:
3a – b = 3 – = – =
Here, we have a non-trivial solution (coefficients 3 and -1 are not both zero) that results in the zero vector. Thus, vectors a and b are linearly dependent. Geometrically, linearly dependent vectors in R² lie on the same line passing through the origin (they are collinear). The span of these vectors is a line, not the entire R².
Examples of Linear Independence:
Consider two vectors a = and b =. To check for linear independence, we set up the equation:
c₁ + c₂ = [6c₁, 0] + [0, 7c₂] = [6c₁, 7c₂] =
This gives us two equations: 6c₁ = 0 and 7c₂ = 0. The only solution to this system is c₁ = 0 and c₂ = 0. Since the only solution is the trivial solution, vectors a and b are linearly independent. Geometrically, these perpendicular vectors span the entire R².
Consider the standard unit vectors in R³: E₁ =, E₂ =, and E₃ =. The equation for linear independence is:
This directly implies that c₁ = 0, c₂ = 0, and c₃ = 0. Therefore, the standard unit vectors in R³ are linearly independent. Furthermore, their span is the entire R³.
Linear Independence, Span, and Basis:
As discussed in our previous conversation, the concept of linear independence is crucial for understanding the span of a set of vectors and the basis of a vector space.
A basis of a vector space is a set of vectors that satisfies two conditions:
The vectors must be linearly independent.
The vectors must span the entire vector space.
For example, the standard unit vectors E₁ and E₂ form a basis for R² because they are linearly independent and their span is R². Similarly, E₁, E₂, and E₃ form a basis for R³.
If a set of vectors spans a vector space but is linearly dependent, it means that there is some redundancy in the set (one or more vectors can be removed without reducing the span) and it is not a basis. To form a basis, you need a minimal set of linearly independent vectors that can generate all other vectors in the space through linear combinations.
In the example of linearly dependent vectors a = and b =, they span a line in R², but they do not form a basis for R² because they are not linearly independent. A basis for the line they span could be just the vector a (or b), as it is a linearly independent set that spans that specific line.
Understanding linear independence is essential for many concepts in linear algebra, including finding the dimension of a vector space, performing matrix operations, and solving systems of linear equations.
Fundamental Matrix Operations
The sources discuss several fundamental matrix operations, which are essential for working with matrices in linear algebra. These operations include matrix addition, matrix subtraction, scalar multiplication, and matrix multiplication.
Matrix Addition
The sum of two matrices A and B of the same dimensions is obtained by adding their corresponding elements. If A and B are both M by N matrices, their sum, denoted as A + B, will also be an M by N matrix where each element (i, j) is the sum of the elements (i, j) of A and B.
For example, if matrix A is $\begin{pmatrix} 1 & 0 & 2 \ 0 & 1 & 3 \ 1 & 0 & 1 \end{pmatrix}$ and matrix B is $\begin{pmatrix} 1 & 2 & 3 \ 0 & 0 & 1 \ 2 & 1 & 3 \end{pmatrix}$, then their sum A + B is calculated element-wise:
The order of addition does not matter (A + B = B + A), which is known as the commutative law for matrix addition. Also, matrix addition is associative, meaning (A + B) + C = A + (B + C). Adding a zero vector to a vector has no effect, and similarly, adding a zero matrix (a matrix where all elements are zero) to another matrix A results in A.
Matrix Subtraction
The difference of two matrices A and B of the same dimensions is obtained by subtracting their corresponding elements. If A and B are both M by N matrices, their difference, denoted as A – B, will also be an M by N matrix where each element (i, j) is the difference between the elements (i, j) of A and B. Subtracting a vector from itself results in the zero vector, and similarly, subtracting a matrix from itself results in the zero matrix.
Scalar Multiplication
Scalar multiplication of a matrix A by a scalar (a real number) $\alpha$ results in a new matrix where each entry of A is multiplied by $\alpha$, effectively scaling the vector’s magnitude. If A is an M by N matrix, then $\alpha$A is also an M by N matrix where each element (i, j) is $\alpha$ times the element (i, j) of A.
For example, if matrix A is $\begin{pmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{pmatrix}$ and the scalar is 3, then 3A is:
The scalar multiplication law for matrices states that for a scalar R and matrices A and B, R(AB) = (RA)B = A(RB).
Matrix Multiplication
The product of an M by N matrix A and an N by P matrix B results in an M by P matrix C, where each entry $c_{ij}$ of C is computed as the dot product of the i-th row of A and the j-th column of B. For matrix multiplication to be defined, the number of columns in the first matrix (N) must be equal to the number of rows in the second matrix (N). The resulting matrix C will have the same number of rows as A (M) and the same number of columns as B (P).
To calculate the element $c_{ij}$, we take the i-th row of A, which consists of elements $a_{i1}, a_{i2}, …, a_{in}$, and the j-th column of B, which consists of elements $b_{1j}, b_{2j}, …, b_{nj}$. The dot product is then calculated as:
For example, if $A = \begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}$ and $B = \begin{pmatrix} 2 & 0 \ 1 & 2 \end{pmatrix}$, their product C = AB is a 2×2 matrix:
Unlike scalar multiplication and matrix addition, matrix multiplication is generally not commutative (AB $\neq$ BA). However, it is associative: (AB)C = A(BC). Matrix multiplication also follows the distributive law with respect to matrix addition: A(B + C) = AB + AC (left distribution) and (A + B)C = AC + BC (right distribution).
Understanding these basic matrix operations is crucial for more advanced topics in linear algebra, such as solving systems of linear equations, finding determinants, and performing matrix factorization.
Properties of Determinants
Based on the sources, here are the key properties of determinants:
The determinant of an identity matrix is one. The source explicitly states that if you have an identity matrix, denoted as $I_n$ for an n x n identity matrix, then its determinant, det($I_n$), is equal to 1. A specific example of a 2×2 identity matrix ($I_2 = \begin{pmatrix} 1 & 0 \ 0 & 1 \end{pmatrix}$) is given where its determinant is calculated as $(1 \times 1) – (0 \times 0) = 1$.
Swapping two rows or columns of a matrix changes the sign of its determinant. If you take a matrix A and create a new matrix $A’$ by interchanging two of its rows or two of its columns, then the determinant of $A’$ is the negative of the determinant of A, i.e., det($A’$) = -det(A). The source provides a notation where $A’$ is referred to as $A_{not}$ when it’s a manipulated version of A through swapping rows or columns.
If a matrix has a row or a column of zeros, its determinant is zero. The source explains that if a matrix contains a row or a column where all the elements are zero, then the determinant of that matrix is zero. An example is given with a 2×2 matrix A = $\begin{pmatrix} 0 & B \ 0 & D \end{pmatrix}$ where its determinant is $(0 \times D) – (0 \times B) = 0$. Similarly, a matrix B with a column of zeros, like $\begin{pmatrix} 1 & 0 & 3 \ 1 & 0 & 4 \ 1 & 0 & 5 \end{pmatrix}$, will have a determinant of zero. This can be understood through the calculation method where if you expand along a row or column of zeros, each term in the determinant calculation will have a factor of zero, resulting in a total determinant of zero.
The determinant of a product of matrices equals the product of their determinants. For two square matrices A and B of the same size, the determinant of their product (AB) is equal to the product of their individual determinants: det(AB) = det(A) $\times$ det(B). The source provides a detailed example with two 2×2 matrices A = $\begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}$ and B = $\begin{pmatrix} 5 & 6 \ 7 & 8 \end{pmatrix}$. First, the product AB is calculated as $\begin{pmatrix} 19 & 22 \ 43 & 50 \end{pmatrix}$, and its determinant is found to be $(19 \times 50) – (43 \times 22) = 4$. Then, the determinant of A is calculated as $(1 \times 4) – (2 \times 3) = -2$, and the determinant of B is $(5 \times 8) – (7 \times 6) = -2$. Finally, it is shown that det(A) $\times$ det(B) = $(-2) \times (-2) = 4$, thus proving the property for this example.
These properties are fundamental for understanding and working with determinants in linear algebra. The determinant provides crucial information about a matrix, such as whether it is invertible.
Linear Algebra for Machine Learning
The Original Text
machine learning is at the Forefront of the Innovation powering the most advanced and transformative systems for the companies like apple Tesla Netflix Amazon open Ai and many others it enables the creation of the intelligent systems that can predict Trends personalized user experience and automate complex tasks to develop this practical applications a deep understanding of the underlying mechanics is important this require is a solid grasp of mathematics behind the machine learning so all these technical details with a particular focus on linear algebra this all-encompassing course explores the linear algebra in an interactive and machine learning Focus manner welcome to the linear algebra for machine learning course you will acquire the critical principles needed to build optimize and analyze sophisticated machine learning models from designing algorithms to enhancing curent Technologies this course provides the mathematical foundations with vital interest for those for pioneering advancements in machine learning for those dedicated to mastering the mathematical aspect and the technical details behind machine learning our extensive 26 plus hour course of fundamentals of machine learning within the mathematics boot camp as well as a separate course offers an in-depth exploration this extensive program includes certification and is tailored for individuals that are serious about advancing their career in the field of machine learning nii engineering this crash course in mathematics will serve you as a great starting point by establishing a robust foundation in linear algebra you will be well prepared to excel as machine learning practitioner equipped with a mathematical knowledge that drives the innovation and efficiency in this field so if you’re ready I’m really excited and without further Ado let’s get started welcome to the course on the fundamentals of linear algebra presented by lunch Academy my name is D Vasan and today we are going to start with some basic concepts that are important for understanding linear algebra linear algebra is one of the most applicable areas of mathematics it is used by pure mathematicians that you will see in universities doing research publishing research papers but also by the mathematically trained scientists of all disciplines this is really one of those areas in mathematics that you will see time and time again appearing in your professional life if you want to become a job ready data scientist or you want to do some handson machine learning deep learning nii stuff but also linear algebra is used in cryptology it is used in cyber cber security and in many other areas of computer science and artificial intelligence so if you want to become this well-rounded professional you want to go beyond using libraries and you want to truly understand the uh mathematics and the technical side of these different machine learning algorithms from very basic ones like linear regression to most complex ones coming from Deep learning like architectures in neural network how the optimization algorithms work how the grad descent Works in all these other different methods and models then you are in the right place because you must know linear algebra such that you will understand these different concepts from very basic ones to most advanced ones in data science machine learning deep learning artificial intelligence data analytics but also in many other applied science disciplines so before starting this comprehensive course that will give you everything that you need to know about linear algebra first I’m going to tell you what we assume that you already know because linear algebra it comes from about third year of Bachelors of different highly technical studies and here we are assuming that you already know certain Concepts so to ensure that this course stays really on the topic of linear algebra and that you understand all these Concepts really well for that we need to be able to know different topics so before we dive into this Concepts let’s familiarize ourselves with the basic prerequisites and notations used throughout this course and you will really need to know this in order to understand this Concepts really well such that instead of memorizing you will actually just hear me once or maybe twice and then every time you hear uh later on or you see it in the papers or in some algorithms you will recognize this is something that we already learned so some key prerequisites overview is here first of all to fully grasp the upcoming material you should be familiar with some basic concept like real numbers Vector spaces so you don’t need to know this idea of vectors though you already most likely are familiar with this given that you know how to plot different lines you know the idea of x’s and y’s and how to plot these different graphs but here we are going to based on this every time when we come close to this Concepts I will refresh you your memory and we will go through this numbers the idea of norms and distance measures because when it comes to the vectors when it comes to the magnitude and all these different topics that we are going to discuss as part of linear algebra knowing the what Norm is and what is the definition of distance what is the length between two points when we plot it in the two dimensional space or three dimens commcial space those are all very basic concept that usually you see as part of a basic pre-algebra or just common algebra courses and lessons in order to truly understand what the new algebra is about to understand this direction of vectors the angle and then the dimensionality reduction how linear algebra is applied for instance in different algorithms in machine learning deep learning data science statistics you really need to understand this Cartesian coordinate system so this is not only important for linear algebra but I assume you already know it given that you have passed those other courses like calculus or usually they are covered as part of pre-algebra or algebra so the Cartesian coordinate system I mean here understanding what is for instance the the common description of them for instance when you when we write like X and then y on the vertical axis and then we can we have here zero and then we can always plot this different plots you know we have a clear understanding what is this Y is equal to X line we understand how by knowing certain points we can plot different plots for instance that this is the Y is equal to X line that here it means that if we have here one then this is just one two this is two so we understand when we have the function of the line and we have a certain value whether it’s our y coordinate or x coordinate then the corresponding coordinates can be be found then you also need to know some basic things that I just didn’t mention right now so for instance that the numbers here can be like one 2 three up to Infinity so you understand this concepts of infinity and then here the same story then here we have minus one you know minus 2 uh and then this is then used later on and we will be touch basing this one we will be describing our vectors and how we can visualize our vectors e the two dimensional space La we have here because this is two dimensional so we have X and Y but we can also of course visualize it in three-dimensional Etc so this idea of basic coordinate system is really important usually covered as part of algebra if not pre-algebra then we have basic triog genetry which means that you need to have a clear understanding what sinus is what cosine is what tangent is and their recip foros and here I mean that you know for instance what is cosine function what is s function you know that you have an understanding for instance that what is this line you know whether it’s a sinus line or cosine line you have also an understanding what this Pi is one thing that I didn’t mention but it it just goes around all these topics some basic things that you understand what is X what is why why we use them and this idea of variables and also you need to understand this idea of square or you know 90° angle and then Pythagoras Theorem here we have the same so what is this relationship between different sides of a triangle uh that is a very unique triangle and that has one of the angles as 90° and this idea of you know the sides how this relates to the signus cosinus tangent cotangent and also how the Pythagorean Pythagorean theorem applies when we have a triangular but it is no longer with angle that is 90° what is the sum of all the angles of a triangle so those are basic stuff that are com commonly covered as part of trigonometric lessons or part of General geometry then another prerequisite is this understanding of identities and equations in triog genometric lessons something part of which I already covered and this just goes around of basic having a basic understanding of algebra and geometry those are super important to understand more Advanced Techniques from linear algebra then we have finally this idea of orthogonality perpendicularity in vectors so this also comes from geometry and from trigonometric lessons so you understand that if we we have for instance these two lines that don’t have any intersections then we are talking about two orthogonal lines and otherwise for instance if we have the two lines like this then we are talking about perpendicular vectors when you have two lines that are actually parallel so they don’t have any intersection and you won’t find any point that is common for the tube so when it comes to this R so as part of real numbers and Vector spaces R represents the set of all real numbers so you can be dealing with for instance and integers like 1 2 three this can Al this will also cover all the negative numbers like min-1 – 2 – 3 but also the floting numbers like 1. 223 and all the other numbers that you can think of those are the set of all real numbers so this is in onedimensional space right so you can see that I’m writing just one number you know two three and other numeric numbers then we have the idea of R2 R3 up to RN where all these numbers they represent in this case the N it represents the N dimensional aidian space so when it comes to this idea of n dimensional numbers so for instance R2 here we just mean 2D plane so I’m pretty sure you are familiar with this idea of for instance x-axis and Y AIS here we are dealing with two dimensional plane so for every point that we can find here we can describe them by assigning them a value X so coordinate X and a coordinate y that’s exactly what we mean by saying that the number can be represented in a 2d plane so here we are dealing with this two dimensional space this is our two dimensional Alan space and every number in here that is part of this R2 can be pictured here can be represented in this visualization so for instance if I have this number and let’s assume that the value on the x- axis is two and we can see here that the corresponding Y is zero I can describe this number which I will call a I can describe this by writing down first the x coordinate which is two and then the y coordinate which is zero so I’m then saying that a which is a point with x coordinate 2 and y coordinate zero it is part of my R2 and it’s part of my two dimensional Alan space when it comes to R3 similar thing we can do with that only in that case we need not just X AIS and Y AIS but we need to add our third dimension so here for instance when it comes to the r Tre then we need to do y AIS we need to have x axis but also we need to have some Zed AIS so such that every time every point in the space we can then describe by x y and Zed coordinates so if we write it in terms of the vector something that we will see very soon as part of our first unit of this course we will then need to write represent every number in this threedimensional Alan Space by writing down first the x coordinate let’s say one and then y coordinate let’s say another one and then Z coordinate which is one or even better even easier let’s do 0 0 0 which means that we are dealing with this initial number which is the center of this three-dimensional Elan space when it comes to the nend dimensional or higher dimensional spaces it’s much harder to visualize therefore usually when it comes to visualizations we do usually we usually only visualize the onedimensional two dimensional and three-dimensional spaces above then it just no longer does make sense to visualize it but we definitely deal with them and they are part of Applied linear algebra so understanding the spaces is very important for analyzing vectors for their interactions and this holds not just for this two dimensional and three-dimensional but really for multi-dimensional spaces let’s Now quickly Define this idea of Norm so the norm of a vector denoted by this V which you can see kind of like similar to the absolute value from pre-algebra you can see here that we have this double straight lines like from absolute value and then we have the name of the vector or the variable name that we are assigning to our vector and then you might notice here on the top of this this Arrow this basically says that we are dealing not with just a variable but really we are dealing with a vector this is really important because you can see that there makes a huge difference if we have for instance just V or V1 I have to say or just V those are really important and things that you need to keep in mind when it comes to linear algebra and trying to differentiate vectors from a point you will notice that when it comes to Norm we can represented it either by this notation or this usually it’s a common notation in machine learning or in data science with this two bars and when we do this we automatically also know that we are dealing with Eline distance we call it also L2 norm and this is something very common and usually used as part of retrogression which is an application of linear algebra and it’s used in regularization so we are regularizing our machine learning algorithms so when you get into machine learning you will see time and time again this notation so next time when you see this then you know automatically that you are dealing with L2 norm and L2 Norm which is also used a lot in machine learning it is referring to the usage of L2 Norm to uh in the retrogression and retrogression or L2 regularization is a very popular regularization techniques as part of machine learning so right now even you can see this intersection of linear algebra or this idea of norms in machine learning all right so now let’s see why we call it actually L2 Norm or often referred as Elan distance so in distance you can see here which is also the in this case this V which describes the norm of the vector v is equal to square roof and then we have all these coordinates assuming that the vector comes from an N dimensional space so you can see here the RN the V Vector the idian distance or the norm of this vector v is equal to square roof and then V1 2qu plus v2^ S Plus and all this in between numbers plus VN s so here basically it means take the square root of V1 squ then V2 squared plus V3 s blah blah blah plus VN squ so basically take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector why this is important this idea of norms and Al IND distance beside of being used in machine learning and why is it chuse so Norms they provide a way to measure the size or the length of a vector in Vector spaces which means that when we want to measure a distance a similarity relationship between for instance vectors then it becomes much easier to use this idea and Alan distance is not only used in regularization techniques like L2 regularization or retrogression but it’s also used in other machine learning or deep learning algorithms as a way to measure the distance or the relationship or the similarity between two different entities those can be variables those can be two people that we want to compare in our algorithm or two entities um for instance the Norms or the Al and distance they are also used as part of K algorith something that you might have heard and if you follow later on the machine learning and the clustering section of machine learning you will see that aladan distance is used as part of C’s algorithm that aims to Cluster observations into different groups so this also yet another highly applicable uh topic that you must know in order to understand different linear algebra top topics but also machine learning topics let’s now talk about simple topic that we must know about and refresh our memory very quickly before moving forward to our next topic that is a prerequisite for this course so the cartisian coordinate system is just a fancy word of describing this idea of X and Y or XY Z when we just want to visualize them and showcase this numbers related to the space so we just learned the and I just quickly was talking about this idea of EX and and Y and how we can visualize that in Plaine so the cortesian coordinate system is a framework for specifying points in a plane or a space using ordered list of numbers so we know for instance when we plot this then here we need to put X and the Y in our two dimensional space or two and we know that here in the middle we have zero and here we have 1 2 3 4 and the same here one two and then three four which means that everyone that is in the indust whether it’s in mathematics in physics in data science or ml or AI we all universally agree on this system we know that this is this ordered list of numbers and we know that if we have for instance a point here then for this point we know that the xaxis and Y AIS is definitely positive even if we know don’t know the corresponding numbers and then once we have more General lines here so not General but specific lines then even know the exact coordinates and values here and we definitely know that this number should be so the x coordinate should be between two and three so first we have the two and then three and not the other way around so this ordered nature helps us to understand how we can put all these different numbers and organize them in our two dimensional space and we also know the corresponding y so we know that for instance our Y is not minus three because it’s lying in here in this part of our coordinate system and not somewhere here where the Y AIS are negative and why do we know that because it’s an ordered list of numbers that we can visualize in this 2D plane and here you also need to keep in mind and we need to remind ourselves about this idea of these four different parts that we got so we have our here the first part the second part the third part and then the fourth you know part of our coordinate system and and here we we are dealing with a two dimensional plane but if we were to deal with the threedimensional plane we no longer have just x-axis and Y AIS where x axis were on the horizontal and y- axis on the vertical but we have our third line which is the Z so we have now three different dimensions so X Y and Z and we are basically extending our two-dimensional plane to threedimensional so this system is fundamental for visualizing and working with vectors geometrically so then we can just use this two-dimensional uh plane in order to visualize this Vector for instance knowing what are all these points that appear on this Vector what is its direction where is it headed you know what is the beginning and then we can also find out all the so the relationship of these vectors with all the other vectors for since if we have not Vector here then we can use the coordinates of them and information about the vectors to understand that we are dealing with two parallel vectors that don’t have anything in common so no intersection points whereas just if we have another Vector like this and we know that here we are dealing with perpendicular you know orthogonal vectors so this is why those this coordinat Cartesian coordinate system is important and it’s not just important for linear algebra but just in general for mathematics and for data science and for AI and you will see this coordinate system time and time again in different visualizations even when you want to visualize the mean of your data or you want to visualize the probability distribution function describing your population from statistics or from data science you want to visualize for instance how your optimization is working or you want to visualize how your model is performing in terms of its Evol ition Matrix for all these cases and for any visualizations this idea of the Cartesian coordinate system is going to become very handy let’s now talk about this idea of angles and the idea of circles radian the pi as well as this degree sign so this comes usually from geometry or tonometry and this is very important when it comes to the vectors because when we have two different vectors then we want understand their relationship do they form this less than 90° or so are we dealing with sharp corner sharp angle or we are dealing with 90° angle so we are dealing with this type of vectors where we have you know 90° or we are dealing with um this type of vectors when the angle is 180° which is by the way uh something that we are referring as pi and here is one thing that is important here is that it’s not just Pi but it’s Pi radians why because in mathematics we also have this idea of Pi which is usually a number that is 3.14 so we should not confuse this Pi with pi radians so the relationship between the two is something that we have also seen as part of our pre-algebra and algebra corses so if it’s something that you want to just refresh your memory on this will be super helpful to check out very initial course on um all these Basics so pre-algebra so this number comes from prealgebra and then this idea of P radians and just in general all this information about what is 180° what is this angle what is 360° and all the information that comes from triog gometry and geometry can be found in our corresponding course so the next topic is the unit circle unit circle is highly related to this idea of radians degrees cosine s but also understanding the cartisian coordinate system will help you to understand the unit circle so this also comes from tonometry and geometry and it’s basically a fancy way of saying we have x-axis we have y AIS we have here zero so our common Cartesian coordinate system only we are trying to focus on this part of the system where we have here one we have here one so on the x-axis we have one and then here minus one here minus one for y AIS and here y the Y is equal to one so we have here all these points and then we have the circle with radius of one so here is this you know this is the radius and here we plot this circle and this will help us to understand this concepts of sinus cosinus you know this Theta is just variable that we use to describe the angle and for instance here we are dealing with 45° this angle is 90 de this entire thing is 360° and half of it so this part only is 180° so those are all important part of understanding this idea of unit circle so you might have already guessed that unit circle refers to this idea that we have here one unit here one unit one unit one unit forming this entire circle so with the radius that is equal to one all right so this is something that is very easy and this comes from the geometry and pre and tri gometry uh you also need to understand this concept of sinus and cosinus and how sinus and cosinus are related to this what do we refer by the sinus and cosine you know what is this what are these points so one Z for instance we understand that here the x is equal to 1 and Y is equal to Z so here this point is simply 1 Z so this point and then we have 2 p radians so what is this idea of P so we know that a p radians so P radians is simply the 180° which means that you also need to understand this concept of P2 which is simply the 90° so you can see here one thing that I forgot to mention you need to understand this concept the relationship between the pi and so Pi radians and radians and this unit circle you need to know that here the Pi / 2 is simply this angle and then the entire Pi is this angle and then this entire thing the entire angle with 360 degrees is equal to 2 pi so 2 pi radians is simply this entire thing so those are very easy Concepts that come from geometry and trometry and if you want to refresh them then had to work those courses because this will help you to understand all these concept from scratch let’s now continue our refreshment when it comes to geog genometric identities and we just spoke about this unit circle we talked about the sinus cosinus it’s really important to relate this back to bit more advanced topics coming from the same do domain and from the same area of mathematics and here we we need to know this concept before learning the your algebra few other things that um would be really great if you know but it’s actually not a must to understand all these different topics it is the idea of Pythagorean identity so don’t confuse this with Pythagoras Theorem this is the Pagan identity so this one that the square of the sign of an angle plus the cosine squared is equal to one and all these different rules that go around the sign and cosine and also the what is for instance the sign 2 Theta which is equal to 2 sin of theta and cosine of theta you know those are all different rules that would be handy to know and if you are so far I assume that you also know geometry and fundamentals to triogen ometry which means that you also know this trules but this might be just a great time to go ahead and quickly refresh your memory on this Concepts because those might become handy in your applied linear arge Applied Mathematics Journey but for now I would say this is not one of the most important things to know to learn this and to go through this course but just something to keep in mind so when it comes to the triog genometric equations uh this can become very handy later on when we want to prove something in linear algebra so to follow along it’s actually a good idea to know for instance what is how you can solve this different equations and this will go back and refer to the unit circle that we just saw for instance if the sinus Theta is equal to 1 / 2 then you will need to quickly remember what is that angle for which the sinus is equal to 1 / 2 then you realize that is actually the angle where you take the p and remember that Pi is equal to 180° and that is the one corresponding to and then Pi / to 6 is simply 180 / it to six so this is basically the 30° so those are things that you can do when you know for instance all these different sinus and cosinus so you have memorized for these different angles so what is the sinus and cosinus for 30 degree for 60° um let me actually remove this to make it easier so this type of problems is very easy to solve when we keep in mind and we memorize what are these different values for sinus and cosinus when it comes to different angles for instance for the angle equal to Z let me actually remove this and clean this part for better understanding so if we have for instance Z degrees then we know that the sinus for this is zero and the cosine of this is one so we are basically dealing so if I plot a unit circle we are dealing with this number so remember that sinus and cosinus those refer to the Y and X on our unit circle so keep this one in mind so if the cosine Theta is then equal to 1 and the sinus so Y is equal to Z we are dealing automatically this number with this number and you can see that here the angle is also zero so here we are dealing with one and zero coordinate so this is our cosine of zero angle and this is then our sinus of zero angle so we automatically even from this graph can see very easily that the S of 0° is equal to 0 and the cosine is equal to 1 all right so let’s quickly also refresh our memory on few other degrees so for the 30 deges which is simply the Pi / 2 6 so this is 30 ° then the sinus or the Y AIS is equal to 1 / 2 and the cosine or the XX value x coordinate is equal to square root of 3 2 so we are dealing with this this corner or angle so 30° so even from here you can see that the coordinates make sense make sense then we have the pi for another famous value which is corresponding to the 45° it simply this angle and for this angle the X AIS which is the cosine so this number is equal to one/ to 2 and then for the sinus the so the y coordinate is equal to 1 / two as square root of two as you might have guessed because in this number the xaxis and y axis is equal to is the same so you can see that this distance and this distance is the same because we are dealing with this type of figure so here we have 45° here we have 45° so this values are the same and this is something that you would know knowing the Pythagorean Pagan theorem so then you can go ahead and refresh your memory for the 60° so here I’m referring to the Pi / to 3 and then the 90° which is the very easy casee this one obviously the xaxis is equal to zero so here you should have zero and the y- axis is equal to one so here you should have one and so on all right so we went into quite detailed here but I think this is a very important topic knowing this idea of a trigonometric equations identities this idea of unit circle are super important because they are highly applicable to different fields in artificial intelligence data science machine learning and will definitely set you apart all right let’s now talk about the law of signs and cosiness those are things that I won’t be going on into too much details I just wanted to quickly showcase to you if you want to get the proof of those definitely check out our corresponding courses but for here I’m assuming that you already know so you know the law of signs which means that if you have this triangle you know you have this different sides so you have an angle a the corresponding side is a and then you have angle B corresponding side is B and then here C and the corresponding side is C then you know that a / to sinus of that angle is equal to B / to the S of that angle and then is equal you see divided to the sign of that angle so basically take this value divided to the sinus of this angle you know right in front of it is equal to taking this value and then dividing into the sinus of this angle so the proof of this low is outside so out of the scope of this course but knowing this will help you to understand different concepts and then the law of cosine is simply saying take the side of a Target angle so in our triangular we have here a we have here angle B and the C and if we go and look into this specific angle so angle C just randomly picking one of the three angles then the side right in front of that angle so the C c^ squ is equal to if we take this you know the other two sides forming that angle so A and B is equal to a s so this is just a constant a distance of this side a 2 + b 2 so this side squar minus 2 * a * B * the cosine of that angle this is what we are referring as the law of cosin quite easy we are not going to prove it again if you want to get the proofs make sure to check our other fores on the geometry and triogen ometry we’re almost done with the prerequisites just a quick refreshment we saw already the norm here is just a notu example what Norm is and on a specific two dimensional Vector when we have for instance that a vector is equal to three and four which means for the First Dimension let’s say on xaxis we have three and then on Y axis is equal to four then the norm or the Alan distance so this is equal to we take the X vol so three and then we Square it so V you can see here this is the case when n is equal to 2 this is simply equal to square root of V1 2 + v2^ 2 and as V1 is equal to 3 so this is our maybe I can make this just V1 and this is my V2 then the norm or the equid in distance for this Vector so this thing is equal to V1 2 + V 2^ 2 which is equal to 3 2 + 4^ 2 and this value is sare root of 25 and it’s equal to five so let’s now see the difference between aladine distance and the norm so you could see here the norm here we have just one vector like here and this Norm it has just two corresponding values into two dimensional space you see here we have just three and then four so this is V1 and V2 when it comes to the Alan distance this is kind of the generalization of this idea of Norm so the Alan distance between two points A and B in RN so in the N dimensional space is the norm of the vector connecting a to B so we see that the norm and the elidan distance are highly related to each other only we are talking about the norm when it comes to one vector but when we have this Vector a a and the vector B this is simply the Alan distance so for the aladine distance we know already this idea of distance how we can measure it and you can see that this comes very similar to what we see here notation and here we are saying well we have this vector and then it has the two coordinates in N is equal to 2 in two dimensional space when it comes to the A distance Elan distance helps you understand what is this distance between two points in an N dimensional space so the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B so for instance if we have a point a and we have a point B we are connecting this and this is the vector connecting these two points then the El distance is simply the norm of this Vector so this is the Alan distance so we can see that the norm and the distance they are highly related to each other in the Alan distance we are using this idea of norm and specifically the norm two as I mentioned before so here you can see that the definition of alodine distance so the distance between A and B the two point is equal to square root of A1 – B1 2 plus a and then here we have basically A2 – b 2 2 and then plus A3 minus B3 s those are things that we cover as part of this dot dot dot and then plus after to the last point when we have a nus bn^ 2 so here what we mean basically is that if we have two points here is a and here is B and this s vector and we know all these different points so A1 B1 A2 B2 A3 B3 blah blah blah and then here a n BN we know all these points lie in here in this distance then we are taking them and using them to calculate the L in distance so here for instance if we have point A and B so in this example let’s do a quick one specific example when we have a point a which has coordinates 1 and two so this is basically A1 A2 and then point B with points in it like B1 B2 you can notice that the da AB so the distance or the eiding distance of these two points which is equal to the norm of this vector or here this is a and this is B and this is this Vector this is equal to square root of 4 -1 so it takes the B1 so this is B1 and this is A1 takes the square and then says plus B2 – A 2^ 2 takes the square root of that and says this equal to 5 now you might be wondering but hey why do we do then instead of 1 – B1 2 we do B1 – A1 2 and the answer to this question lies in the uh properties that we learn as part of prealgebra because it doesn’t matter when we we take A1 – B1 2qu or B1 – A1 squ because this squared ensures that it doesn’t matter which one we take first and subtract the other now the proof of that is outside of the scope of this of course this is part of pre-algebra but I just wanted to put this out there to ensure that you are seeing what we are seeing here because here it says A1 minus B1 but in this example we are taking instead depth B1 and we are subtracting A1 this is a common thing that we do in P algebra and just in general in different culating distance or distance related cases so I just wanted to put this here to ensure that later on this is something that can be clear from the first view right and in here we will quickly refresh our memory on the Pythagorean theorem which basically says in the right angle triangle so if we have this type of triangle so here we have 90° this is a right angle triangle the square of the length of the the side opposite to the right angle so this side this we of refer C and this as B uh and then a those two are not very important but this is commonly referred by C so the the side opposite to the right angle then we know that the square of the C so C squ is equal to a 2 + B2 this is super important theorem and a fundamental principle for defining the Norms the distances in equity and spaces in and in many other applications so the angles play a crucial role in understanding the direction of the vectors and you know how they can be measured in degrees or in radians we saw also the pi radian this idea of you know that the pi radian is equal to 180° those are all very important when it comes to linear algebra and just in general application of mathematics in machine learning in Ai and other applications the relationships between these angle measurements and the triog genometric functions is foundational in solving different problems that are about these vectors and their orientations for instance this angle of sign cosine you know what is this idea of tangent they are very important just to give you an idea the um a t a tangent is specifically used as part of the activation functions we call tank activation function and knowing this tank will help you to understand the activation functions that I use as part of deep learning which are more advanced machine learning type of models and they are fundamentals in all these different new and Cutting Edge techniques large like large large language models Transformers encoder and decoder based algorithms Etc they’re also important in this idea of computing dot products so very important and a must know when it comes to linear algebra so this is just an simple example when it comes to this right angle triangle and Pythagorean theorem and how it is applied I will skip this for now it’s also important to understand this idea of orthogonality so the two vectors let’s say A and B they are orthogonal to each other if their dotproduct is zero so later on as part of the vectors when we will talk about dot product we will see what we mean when we say that the dot product is equal to zero and here you can even see that if the a norm if the a vector so you see here and B Vector if those vectors if we multiply them to each other their dot product is equal to zero it means they are orthogonal so this angle that they form is equal to 90° orthogonality implies that the vectors from the from a right angle with each other they are in you know we we are dealing with that in our2 in our tree so they are super important way it comes also to visualizing them correctly this concept is visually represented all this uh you know Vector a and then Vector B and they are perpendicular in the 2D uh coordinate system all right so when it comes to the applications of orthogonality orthogonality plays a crucial role in various aspect of linear algebra it’s fundamentally in defining Vector spaces subspaces in solving systems of linear equation later on when we pass the vector ideas and we go on to the matrices solving linear systems so equations with many unknowns and then we use this idea of reductions or gaussian reductions we will see how this idea of orthogonality can be important and how also it relates back to the norm of two vectors so it’s fundamental in defining all these different Iden ities and solving system of linear equations and also orthogonal vectors are used in finding the shortest distance from point to the plane um something that is important when it comes to the optimizations and here you can see an example the vector a which is equal to 2 three and then Vector B which is equal to minus 3 and 2 you can see that when we multiply 2 by minus 3 so we obtain basically the dot product by the way this is something that we are going to cover also part of the squares but for now you can see that if we take this number we multiply with this so 2 * – 3 we take this number multiply with this so we take three and multiply with two you can see that this equal to minus 6 this is equal to 6 so – 6 + 6 is equal to zero so you can see that the dotproduct of these two vectors is simply equal to zero and this is what we are referring as orthogonality this means that these two vectors form a right angle where we see here this angle is equal to 90° why this prerequisites matter and why I mentioned those understanding this concept is very crucial they underpin this geometric interpretation of linear algebra they will help you to better understand these Concepts and not just to memorize them but really understand and later on when you go into your machine learning and AI journey and your data science Journey seeing these Concepts will help Q to better understand those different algorithms this optimization techniques what we mean when we say we want our optimization algorithm to move towards local minimum Global minimum this idea of movement this idea of vectors later on will you will also understand this different concepts in deep learning how these models work how the neural networks work and those are essential Concepts that you need for solving different systems of linear equation a core part of this course they also help you in visualizing vectors spaces which are critical to understand this concept of linear algebra the applications of linear algebra when it comes to the real world applications so those are things that you can definitely Master by following some of our other courses but for this course I assume that you are already familiar with these Concepts right so now we are ready to actually begin and with this prerequisite it in mind you are prepared to start your linear arbra Journey we are going to learn everything in the most efficient way in such a way that you will learn the theory you are going to see many examples we are going to learn everything in detail but at the same time you’re going to learn the must know Concepts and I’m not going to overwhelm you with this most difficult concept that you will not be seeing in your career I’m going to give you this bare minimum when it comes to really knowing the must know for linear algebra such that you will be ready to apply linear algebra in your professional Journey whether you want to get into machine learning deep learning artificial intelligence data science knowing these different concepts in linear algebra you will be a pro in your field going to give you everything that you need the theory examples implementations everything in detail but at the same time you will be doing that in the most efficient and time saving way so without further Ado let’s get started let’s Now quickly Define this idea of Norm so the norm of a vector denoted by this uh uh V which you can see kind of like similar to the absolute value from pre-algebra you can see here that we have this double straight lines like from absolute value then we have the name of the vector or the variable name that we are assigning to our vector and then you might notice here on the top of this this Arrow this basically says that we are dealing not with just a variable but really we are dealing with a vector this is really important because you can see that there makes a huge difference if we have for instance just V or V1 I have to say or just V those are really important and things that you need to keep in mind when it comes to linear algebra and trying to differentiate vectors from a point you will notice that when it comes to Norm we can uh represented it either by this notation or this usually it’s a common um notation uh in machine learning or in data science um with this uh two bars and um when we do this we automatically also know L2 norm and this is something very common and uh usually used as part of uh retrogression which is an application of um linear algebra uh and it’s used in uh regularization so we are regularizing our machine learning algorithms so when you get into machine learning you will see time and time again this um notation so uh next time when you see this then you know automatically that you are dealing with L2 norm and L2 Norm which is also used a lot in machine learning it is referring to the usage of L2 Norm to in the uh R regression and R regression or L2 regularization is a very popular regularization techniques as part of machine learning so right now even you can see this uh intersection of linear algebra or um this uh idea of norms in machine learning the norm of this vector v is equal to square roof and then V1 squ plus v2^ squ plus and all this in between numbers plus VN squ so here basically it means take the square root of V1 squ vs2 squ plus V3 squared blah blah blah plus VN squ so basically take all the units that form this vector and then so are on this vector and use them Square them and then add them and then take the square root of that that’s the distance or I have to say the norm of this Vector we saw already the norm here is just a not example what the norm is and um on a specific two-dimensional Vector when we have for instance that a vector is equal to three and four which means for the First Dimension let’s say on x axis we have three and then on Y axis is equal to four then the norm or the Alan distance so this is equal to we take the x value so three and then we Square it so V you can see here this is the case when n is equal to 2 this is simply equal to sare root of v1^2 + v2^ 2 and as V1 is equal to three so this is our maybe I can make this just V1 and this is my V2 then the norm or the equ in distance for this Vector so this thing is equal to V1 s + v2^ 2 which is equal to 3^ 2 + 4^ 2 and this value is square root of 25 and it’s equal to 5 let’s now see the difference between aladine distance and the norm so you could see here the norm here we have just one vector like here and this Norm it has just two corresponding values into two dimensional space you see here we have just three and then four so this is V1 and V2 when it comes to the Alan distance this is kind of the generalization of this idea of Norm so the aladan distance between two points A and B in RN so in the N dimensional space is the norm of the vector connecting a to B so we see that the norm and the Alan distance are highly related to each other only we are talking about a norm when it comes to one vector but when we have this Vector a and the vector B this is simply the aladine distance so for the aladine distance we know already this idea of distance how we can measure it and you can see that this comes very similar to what we see here notation and here we are saying well we have this vector and then it has the two coordinates in N is equal to 2 in two dimensional space when it comes to the Aline distance aladine distance helps you understand what is this distance between two points in an N dimensional space so the aladan distance between two points let’s say A and B in N dimensional space is the norm of the vector connecting a to B so for instance if we have a point a and we have a point B we are connecting this and this is the vector connecting these two points then the aladine distance is simply the norm of this Vector so this is the aladine distance so we can see that the norm and the distance they are highly related to each other in the Alan distance we are using this idea of norm and specifically the norm two as I mentioned before so here you can see that the definition of aladine distance so the distance between A and B the two point is equal to square root of A1 – B1 2 plus a and then here we have basically A2 minus B 2^ 2 and then plus A3 – B3 2 those are things that we cover as part of this dot dot dot and then plus up to the last point when we have a n minus BN 2 so here what we mean basically is that if we have two points here is a and here is B and this s vector and we know all these different points so A1 B1 A2 B2 A3 B3 blah blah blah and then here a n BN we know all these points lie in here in this distance then we are taking them and using them to calculate the L in distance so here for instance if we have um point A and B so in this example let’s do quick one specific example when we have a point a which has coordinates 1 and two so this is basically A1 A2 and then point B with uh points in it like B1 B2 you can notice that the da AB so the distance or the equid distance of this two points which is equal to the norm of this um Vector but here this is a and this is B and this is this Vector this is equal to square root of 4 minus 1 so it takes the B1 so this is B1 and this is A1 takes the square and then says plus B2 – A 2^ 2 takes the square root of that and says this equal to 5 now you might be wondering but hey why do we do then instead of 1 minus B1 s we do B1 – A1 2 and the answer to this question lies in the um uh properties that we learn as part of prealgebra because it doesn’t matter when we take uh A1 – B1 2 or B1 – A1 squ because this squared ensures that it doesn’t matter which one we take first and subtract the other now the proof of that is outside of the scope of this um course is this is part of pre-algebra but I just wanted to put this out there to ensure that uh you are uh seeing what we are seeing here because here it says A1 minus B1 but in this example we are taking instead depth uh B1 and we are subtracting A1 this is a common thing that we do in um pre-algebra and just in general uh in different um Alan distance or distance related cases so I just wanted to put this here to ensure that uh later on this is something that can be clear um from the first view why this is important this idea of norms and equ in distance beside of being used in machine learning and why is it used so Norms they provide a way to measure the size or the length of a vector in Vector spaces which means that when we want to measure a distance a similar ility uh relationship between for instance vectors then it becomes much easier to use this idea and El IND distance is not only used in regularization techniques like L2 regularization or retrogression but it’s also used in other machine learning or deep learning algorithms as a way to measure the distance or the relationship or the similarity between two different entities those can be variables those can be two people that we want to comparing our algorithm or two entities um for instance uh the um Norms or the Al and distance they are also used as part of K algorithm something that you might have heard and if you follow later on the machine learning and the clustering section of machine learning you will see that elidan distance is used as part of C’s algorithm that aims to Cluster observations into different groups so this also yet another highly applicable uh topic that you must know in order to understand different linear albra top topics but also machine learning topics welcome to the course on the fundamentals of linear algebra my name is D Vasan and today we are going to start with some basic concepts that are important for understanding linear algebra linear algebra is one of the most applicable areas of mathematics it is used by pure mathematicians that you will see in universities doing research publishing research papers but also by the mathematically trained scientists of all disciplines this is really one of those areas in mathematics that you will see time and time again appearing in your professional life if you want to become a job ready uh data scientist or you want to do some handson machine learning deep learning and AI stuff but also linear algebra is used in cryptology it is used in cyber security and in many other areas of computer science and artificial intelligence so if you want to become this well-rounded professional you want to go beyond using libraries and you want to truly understand the uh mathematics and the technical side of these different machine learning algorithms from very basic was like linear regression to most complex ones coming from Deep learning like architectures in neural network how the optimization algorithms work how the gradient descent works and all these other uh different methods and models then you are in the right place because you must know linear algebra such that you will understand these different concepts from very basic ones to most advanced ones in data science machine learning deep learning artificial intelligence data analytics but also in many other applied science disciplines so before starting this comprehensive course that will give you everything that you need to know about linear algebra first I’m going to tell you what we assume that you already know because linear algebra it comes from about third uh year of Bachelors um of different uh highly technical studies and um here um we are assuming that you already know certain Concepts so uh to ensure that this course stays really on the topic of linear algebra and that you uh understand all these Concepts really well for that we need to uh be able to know different topics so before we dive into these Concepts uh let’s familiarize ourselves with the basic prerequisites and notations used throughout this course and you will really need to know this in order to understand this Concepts really well such that instead of memorizing you will actually just hear me once or maybe twice and then every time you hear uh later on or you see it in the papers or in some algorithms you will recognize um this is something that we already learned so so uh some key prerequisite overview is here um first of all to fully grasp the upcoming material you should be familiar with some basic concept like real numbers Vector spaces so you don’t need to know this idea of vectors though you uh already most likely are familiar with this given that you know how to plot different uh lines you know the idea of x’s and y’s and how to plot these different graphs but um here here we are going to touch base on this every time when we come close to this Concepts I will refresh you uh your memory and we will go through this numbers the idea of norms and distance measures because when it comes to the vectors when it comes to the magnitude and all these different uh topics that we are going to discuss as part of linear algebra knowing the what Norm is and um what is the definition of distance what is the length between uh two points when we plot it into two-dimensional space or three-dimensional space those are all very basic concept that usually you see as part of a basic pre-algebra or just uh common algebra courses and um lessons in order to truly understand what the algebra is about to understand the direction of vectors the angle and then um the uh dimensionality reduction how linear algebra is applied for instance in different algorithms in machine learning deep learning data science statistics you really need to understand this Cartesian coordinate system so uh this is not only important for linear algebra but I assume you already know it given that you have passed those um uh other courses like uh calculus or usually they are covered as part of pre-algebra or algebra so the Cartesian coordinate system I mean here understanding uh what is for instance the the common um description of them for instance when you when we write like X and then y on the vertical axis and then we can uh we have here zero and um then uh we can always plot this different plots you know we we have a clear understanding what is this um Y is equal to X line we understand how by knowing certain points we can plot different plots for instance that this is the Y is equal to X line that here it means that if we have here one then this is just one two this is two so we understand when we have the function of the line and we have a certain value that is our y coordinate or x coordinate then the corresponding uh coordinates can be found then um you also need to know um some basic things that I just didn’t mention uh right now so for instance that the numbers here can be like one 2 three up to Infinity so you understand this concept of infinity and then here the same uh story then here we have minus one you know minus 2 um and then this is then used later on and we will be uh touch basing this one we will be describing our vectors and how uh we can uh visualize our vectors either two dimensional space like we have here because this is two dimensional so we have X and Y but we can also of course visualize it in three-dimensional Etc so this idea of basic coordinate system is really important um us usually covered as part of algebra if not pre-algebra then we have basic triog gometry which means that you need to have a clear understanding what sinus is what cosine is what tangent is and their reciprocals and here I mean uh that you know for instance um what is cosine function what is s function um you know that you have an understanding for instance that um uh what is this line you know um whether it’s a sinus line or cosine line you have also an understanding what this Pi is um one thing that I didn’t mention but it it just goes um around all these topics some basic things that you understand what is X what is why why we uh use them and this idea of uh variables uh and also uh you need to understand this idea of square uh or you know a 90° uh angle and then uh pagas theorem here we have the same so what is this relationship between different sides of a triangle uh that is a very unique triangle and that has one of the uh angles as 90° um and uh this idea of um you know the sides how this relates to the sinus cosinus tangent cotangent um and also um how the Pythagorean um pagan theor applies when we have uh a triangular but it is no longer with a angle that is 90 degree what is the sum of all the angles of triangle so those are basic stuff that are com commonly covered as part of uh trigonometric uh lessons or part of General geometry then another prerequisite um is this uh understanding of uh identities and equations in triog genometric um lessons something part of which I already covered and this just goes around of basic having a basic uh understanding of algebra and geometry those are super important to understand more Advanced Techniques uh from linear algeb then we have finally this idea of orthogonality perpendicularity in vectors for instance if we have um two lines like this then we are talking about uh perpendicular vectors is when you have two lines that are actually parallel so they don’t have any intersection and you won’t find any point that is common for the TU hi there so let’s get started with our first module which is foundations of vectors in this module we are going to talk about fundamentals of linear algebra vectors we are going to make a differentiation with between scalars and vectors we are going to Define them so first we will learn the theory then we will Implement them into practice by plotting them by looking into different examples then we will look into this representation of vectors by looking into the magnitude and the direction of it and the representation of them just in general we are going to plot them in our coordinate system then we are going to see the common notational vectors and indexing of them vectors are super important when it comes to linear algebra and application of it and uh they matter not only in mathematics but beyond so uh vectors help us in many ways from figuring out how objects move to solving math problems in science and just in general in technology including in data science machine learning artificial intelligence Etc they are super useful tool so uh let’s start our journey with looking into scalers so scalers they are displaying numbers and by definition a scaler is a single numeric volume often representing magnitude or quantity for example uh scalers can be describing um the temperature outside for instance the temperature of um 22° uh can be represented by a scaler or a height of a person can be represented it’s a scaler so let’s assume we have a scaler that we will Define by a letter s is just a variable this scaler is then equal to 22 for instance and we are measuring Dr it in degrees so it means that uh if this s measures a room temperature then the scaler s which is equal to 22° which represents the room temperature it can be for instance 18° or 9° if it’s very cold uh it just measures a single volume it represents just a single number or it can be for instance 17 100 2.22 so all this they are just scalers they represent a single numeric volume they often represent a magnitude or a quantity very soon we will see that scalers they are a value that represent the magnitude of a vector so uh now when we are clear on this very basic concept of scalers let’s actually move to this idea of vectors so by definition a vector is an ordered array of numbers which can represent both magnitude and direction in space so uh vectors they are bit more they represent bit more than scalers they are numbers that also show direction like a car speeding down the highway or a ball uh being thrown for instance uh when it comes to our previous example where we were using this uh uh room temperature as a way to uh think about the scaler a scaler for instance scaler that we just saw was this room temperature room temperature which was 22° when it comes to the vector vector is different for Vector for instance we can have an example when a bird for instance bird it flies flies at 10 kilometer per hour and I I also add here another information which will make this as a vector which is that it flies South so here as you can see what I’m doing is that I’m not just oh let me actually remove this part to make it easier to understand okay so uh in this example let me write it down that the example Birds flies South at 10 kilom per hour so you can see that I’m not just adding the scaler which is in this case the magnitude we will see very soon the formal definition of it so I’m writing down the speed I’m defining the speed but also the direction so I’m saying I know that the bird is is flying south that’s the direction and I know also the speed of it which is the magnitude so 10 km hour so here in the vector I have much more information than in the scaler because in the scaler I just got temperature room temperature single value but in case of a vector I not only have a magnitude or speed like 10 kilm per hour but I have extra information which is the direction of it for instance flying to the South so let’s now look into some real examples and plotting them to make more sense out of this ideal vectors and what is this magnitude what is the direction so let’s assume we have a 2d plane so we have x-axis we have y AIS here like usual we have our z0 Center and we want to plot a simple Vector so uh usually the way we represent Vector in tutorials just writing down is by writing the name of the vector this can be just a a random name let’s assume that it’s a v letter V and then on the top we are always adding this Arrow so this Arrow it says and it tells the person who is reading that we are dealing with the vector arrow on the top is that reference so let’s assume this uh vector v it starts from the center of our coordinate system and it goes to this point so let’s say in here this is our vector v so let’s assume that this point in here is equal to 4 which means that the x coordinate is four and the y coordinate is zero as the uh uh Arrow it just as the point in here it has a a y value of zero so you can see that it goes straight from zero to to this one to this point okay so what tells this Vector uh to us is that we have a value that describes the length of the vector so it goes from 0 to 4 which means that the length is equal to unit 4 so it’s equal to four um and we have just learned and we were just talking about that the magnitude is the length in this case so the length describes the magnitude in this case so this means that the magnitude of this Vector is equal to four and then um what else we can see here we can see the direction of the vector which means that the direction is also something that we can see here this is the direction of the vector so this going straight from this point to this point in a horizontal Al way so independent whether I plot this Vector from 0 to 4 in here or in here or in here or in here or in here in all cases as long as the length is this I’m dealing with the same Vector because I am basically in this entire R2 space I have exactly the same Vector all I care is about the magnitude and the Direction Where will this Vector start and where will it end I am not interested I’m interested that the uh that the magnitude in this case the length is equal to the direction of the vector so let’s now look into another example where we go a bit more difficult on our coordinates and on our Vector we already saw that we had this Vector where we went let me change the color so this was our vector v and it went from zero till four so this point to be more specific is so this Vector it goes the vector B it goes from 0 0 to 4 0 so the coordinate X was four and the Y was Zero now let’s plot another one um where the direction is no longer horizontal for this Vector let’s call it Vector W and for this vector w we will again start with Z 0 so we will start again in here but this time we will go bit like this so let’s say we go all the way to this point so this point has a value for an x- axis of three and for y axis it has a value of four which means it goes from this point to this point and this is the direction of our vector v so it goes 2 3 4 because this point is 3 0 and this point is 04 so xaxis is 0 x coordinate and y coordinate is four so now you can see that the direction of this Vector is like this while the direction of the vector B was like this and like in case of vector v i again no longer care about where exactly my Vector W starts and ends but all I care is about its magnitude so the length and the direction so for instance I can have the same Vector in here the same Vector in here as long as the length the magnitude is the same and the direction I am dealing with the same Vector that’s all I care so the magnitude and the direction is all that you care about all right so now about the length um that’s uh something that you can see very easily from this specific example because by using the Pythagoras Theorem or P Pagan theorem we can see very quickly that as the length of this side of our right angle 30° so right triangle we can see that this side is three this side is 4 which means that this side is five because 4 2 + 3^ 2 then we take the square root of that is square root of 25 and it’s equal to 5 so the length or the magnitude of this vector v is simply equal to five all right this was about this uh specific vectors let’s now look into the uh common representation of the vectors so we always use the magnitude as well as the direction you know to represent the vectors and they commonly are represented by two different uh ways let’s now look into the first way that the vectors can be represented and then we will move on to the next one so when it comes to the vector v so we saw that vector v was moving from 0 till uh to the point of 40 so we can represent the vector B by 4 and Z when it comes to the vector w we can represent that uh Vector so Vector w we can again do the parenthesis and we can say that it’s equal to 34 so by using the coordinates from the coordinate system we can then represent our uh vectors so this is just one way of representing a vector another way of representing these vectors is by using this Square braces given that we are in a two dimensional space first we will mention here the four then we will mention the zero in here two so we can say three and four this is yet another way of representing the vectors in a two dimensional space so if we were to have a three dimensional space so let me actually show it on a new page so if we were to um if we were um to have vectors in three dimensional space so we are dealing with R3 so we have have points that can be described by X Y and Z so coordinate space like this so X and then Y and then the Z then every point so let’s say we have this Vector then we had to represented by a value let’s say x uh X1 y1 and Z1 or um better let me actually use a different letters a b and C and this would be my vector v and I could also represent this vector v is the same so vector v can be represented as a b and c so one thing that you can notice is that unlike the R2 now I have three different entries what we are also referring as rows and we just got one column so um we can uh of represent and usually that’s a common way of representing vectors by using this um columns so columns help us to represent our vectors and you can see very clearly then when it comes to the two-dimensional space so when we have R2 so then our vectors have just two rows so three and four 4 Z like in here when it comes to three dimensional space we have three entries and so so the same holds of course also for for instance R5 therefore for R5 our vectors so coordinate space can be for instance X Y Zed and then GMA and then let’s say Delta and then the coordinates of a vector in that space can be V and then arrow is equals sh and then we would have uh let’s say A B C D E you get the idea so depending on the space the coordinate space and and the dimension of that space then the corresponding vectors can be represented accordingly so the vectors are quantities that have both magnitude and direction as we just so distinguishing them from scalers which only have magnitude so we saw that the scalers got only magnitude while in case of vectors we saw both for the vector v and for the vector w we didn’t we didn’t only have the magnitude so the length of Vector but also the corresponding Direction so uh when it comes to the um vectors so this is exactly what we just saw in our example a vector in a two dimensional space so in R2 uh can be represented by using this Square braces and the corresponding entries for X and Y where X is basically the x coordinate in our coordinate system so in our X and Y system whenever you have this x and y coordinate then uh this x coordinate Will then describe your magnitude and the y coordinate Will then describe your second entry that you need to put when representing your vectors so here the X and Y indicate the movement in the horizontal and in the vertical Dimensions respectively so for the X’s it’s always the x coordinate so how far you move towards the horizontal Direction in here in here or independent in here so always take the x coordinate that is the value that you need to put first and then the Y need to be put it in here so indexing in vectors when it comes to the um indexing the standard mathematical notation uh indices in the N vectors goes from I is equal to 1 to I is equal to n so the um notation here can be a bit ambiguous so AI uh could mean the E element of AI uh the a vector or the each Vector in a collection so let’s start with a simple one and then move on to this next part so what this means and what this means we will look into now so uh usually uh when we have a um n dimensional space we are having hard time visualizing it therefore we use this two dimensional space or maximum threedimensional space in order to get an understanding of what these vectors are so we just saw examples of them uh when uh creating our vectors in um V and V uh and W in uh R2 and also in R3 but we can have similar vectors also in R4 in R5 or all the way down to RN where n can be 100 200 500 any number as large as you want the thing is is that visualizing R4 R5 RN is very hard but we can still benefit from this great properties of the vectors metrices and in general linear algebra in order to describe different things that have more than three dimensions therefore we have this a bit more ambiguous notation where we use RN and this n can be any real number and it can be all the way to Infinity so very large number and uh let’s say we have a vector in this RN then this Vector is usually described by using similar Square uh brackets like before only with uh more entries so like before we got just one column so that’s something that we didn’t uh change but here we have instead of just two entries or three entries like in the two dimensional or threedimensional spaces now we have A1 A2 A3 all the way down to a n minus one and a n so we got in total n elements in our column and this describes our uh single Vector so this Vector in an N dimensional space this we can call also a so one thing that we just so is that it was saying in our definition and notation that uh we might also be dealing with the E Vector in a collection which means means that sometimes you will see this while here the A1 A2 they are vector themselves so here we saw that these are just entries so A1 is a number A2 is a number A3 is a number a n is just a number but it’s also possible uh when you have a much more difficult and complicated case that you got an A let’s write it down with a capital letter A which is equal to A1 or let’s actually remove this so we got let’s say A1 A2 A3 all the way down to a n minus one and a n where you can already see what is going on so instead of having just a number as an entries instead we have vector vors in here so our first element is actually Vector our second element is actually Vector so A2 Arrow A3 Arrow all the way down to a n arrow so while here this can be for instance some numbers let’s say 1 one one all the way down to one one here we have a vector vector another vector and all the way down here you had another Vector where for instance let we remove this part where for instance A1 arrow is actually equal to a11 A1 2 a13 all the way down to A1 n one thing that you will notice here is that unlike in here here I got double indices so I got here a11 and then a12 and then a13 all the way to A1 n so the first index it doesn’t change as I have here a one so I’m writing down the index corresponding to this Vector but the second index it changes per entry indicating which element specifically in the vector I’m talking about so from the first index you can identify the Vector that I’m referring to which is A1 and from the second index you can see the corresponding um entry or the value that that um element is positioned in this Vector so you can see that this values for instance in the um Vector one so A1 to be more specific but then it is in the first position this is in the second position in the third position all the way down to the end position so so this is something that is really important to understand well because this notation is going to appear time and time again across various applications of matrices and vectors so is really important to understand well therefore I want to go one more time through this to make sure that we are clear on what this indices represent so whenever we have an index uh an a vector that we want to uh represent and it’s um it has just um it is just a vector which means that it’s not a nested vector vector in a vector then um we can Define it by let’s say a and then on the top an array and it’s equal to and here we can have A1 A2 all the way down to a n so you can see what we are also referring as dimension of this Vector is equal to n by 1 so I got n entries and just one column so n by one which means that this already gives me indication that most likely this A1 is a number this A2 is a number this a n is a number so let’s say this equal to one two uh three blah blah blah and then here I have let’s say 100 but if I’m dealing with the nested Vector later we will see that this can be repres represented by a matrix then um I can also Define this by Capal letter A which is a common way to refer to either matrices or nested vectors and then this is equal to A1 Arrow A2 Arrow A3 Arrow this already sends a message to the reader that we are dealing with no longer a constant within a vector but rather vectors in a vector and uh what can we see here is that the dimension of this nested vector or which we can also refer to as a matrix here the number of rows so the number of entries this elements we can see is equal to n but then this time the number of values that form these vectors is no longer one because we’re are not dealing with just a constant this is not some constant but rather this is yet another Vector so let’s assume this Vector has a length of M so let’s say this has a length of M then the dimension of this Matrix a is equal to M so something that we will see also when talking about matrices so let me actually clarify this bit more for better understanding let’s say we look into one of those um one uh one other example of an entry so let’s say we look into this specific Vector which is in the um the third uh Vector within this Vector capital A so this A3 Vector so one thing to see here already is that I assumed that these vectors they got M elements and keep in mind that all these vectors they should be of the same size so it means that I already know that this specific Vector A3 has M elements so M elements so I’m representing this uh A3 Vector from here I’m taking this out from this entire uh nested a vector and I just want to represent this and now unlike these elements that got an arrow on the top this time I will have uh constants forming the A3 Vector so I no longer have vectors but I have elements in it so in here I will have a a let me actually write down all the A’s but to refer and to make sure that I recognize that I’m dealing with the third a vector so a tree Arrow here I will put tree tree all the way here three so they all come from the same third A3 Vector but then their positions is different because this is let’s say uh one two and then all the way down to M position so this indices help us to keep track what are the um position that these values are taking part in the vector A3 errow this might seem bit complicated at the moment but whilst we move on onto bit more complex material like uh matrices it will make much more sense this is bit of an extra I just wanted to Showcase this but this is what uh is at its core and what you need to uh understand at the moment to understand this concept of vectors so you need to know that vectors can be represented by this arrow on the top so let’s say Vector a and it has let’s say n elements then you can write this square brackets and then you will need to mention A1 A2 all the way to a n which means that you have n different entries describing your vector so you have A1 which is the first element in your vector A2 the second element all the way to a n which is the end element but here you can see for instance so if I add here A3 that uh A1 is simply equal to 1 A2 is equal to 2 A3 is equal to 3 all the way to a n is equal to 100 so these numbers I’m basically taking and I’m representing them I’m putting them in here here within Square braces in order to get a representation of my Vector so my Vector a has all these different entries and different entries and it starts with one and it ends with 100 this is a vector and then when it comes to the vectors within vectors here we need to be a bit more careful cuz here we not just have uh constant values forming a vector but we have vectors that form yet not vectors so our Vector a our nested Vector a which we uh later will refer as Matrix a has actually entries that also are vectors so we have A1 Vector A2 Vector A3 Vector they are not just constants but on their own they are vectors so here for instance we have defined also an example of it we have said let’s look into this third specific Vector that is part of a which is A3 uh vector and uh that one has M different elements here we have then the index referring to the which Vector from the nested Vector a it is which is the third one because we have taken it from here but then on its own this Vector has different members and different members to be more specific therefore we have also an index to keep track of the position of this value one to up to M and this can be yet another uh this time it can contain some elements an example of which is for for instance 0 1 2 all the way to let’s say 500 and this can be different numbers it doesn’t need to be ordered it doesn’t need to have a specific pattern they can be just random numbers describing this A3 Vector so hopefully this makes sense if it doesn’t don’t worry because we are going to see this time and time again I just wanted to give you a brief of an intro such that you can uh remember this when we come uh back to bit more uh complex topics like uh indexing in matrices so now let’s talk about special vectors and operations here we are going to talk about zero vectors unit vectors the concept of sparcity in vectors as well as vectors in higher Dimensions like we just saw about this nend dimensional space we will also talk about different operations we can apply when it comes to vectors like uh addition subtraction and then later on in the next module we will also talk about multiplication we will also be looking into the properties of vector addition after we have looked into some detailed examples when it comes to operations on vectors all right so let’s start with the zero vectors and unit vectors when it comes to the zero vectors you can see here already that U the zero and arrow on the top it basically refers to the vector like we saw before only with the difference that all its me numbers are zero so you can see here that we have zero and then an arrow and then underneath here we have some number three and then this is described by this common representation with the square braces and then three different members 0 0 0 so all zero and then it says in R Tre okay so why are we doing this well uh when it comes to uh different linear oppr sometimes we just need to add zero vectors or we just want to create zero vectors it’s just easier to work with we want to uh just create an empty uh Vector we want we know the length but we want to keep it empty such later on we can add something on the top or knowing that when we add a zero on a number the number stays the same we can make use of this property to uh do different um uh tricks when it comes to programming in Python in color or in C++ Etc so therefore this idea of zero vectors can become very handy now one thing that you need to notice here is that we are not just writing down this zero to emphasize we are dealing with a vector but like uh before we have this error on the top emphasizing that we are dealing with a vector then what we are doing is that we are also adding the dimension of this V Vector so in what dimension in what space are we um uh creating this zero Vector that this Vector is located is it in R2 in RN in R3 in this specific case you can see that in this example the uh index that we got here is three which basically indicates we are dealing with a zero Vector in threedimensional space so in the R3 uh in general we would just knowe this by n sking the uh notation general which means that we are dealing with 0 0 all the way down to zero so it has n by one dimension in our n all right so this is about zero vectors it is just a way to uh make our programming life easier also to use it in different algorithms when it comes to bit more advanced algebra uh the next type of special vectors that we will look looking to is this unit vectors so vectors with a single element equal to one and all the others zero denoted as EI for the E unit Vector in N dimensions are referred by unit vectors so uh what we mean here when it comes to the unit vectors um if we have for instance E1 it means that we have a vector where the is in this case the first element is equal to one so you can see that E1 is equal to 1 0 0 so in the first element we got one and the remaining is zero and this is really important that we are dealing with vectors that contain only element of zeros and ones and the only member that is equal to the only element in that Vector that is equal to one is the E element in the entire Vector all the remaining ones are zero and you can see here that the dimension is no longer specified but just the um index of the entry where the um uh the uh one is located so let’s look at another example in here for instance when it comes to the um uh unit Vector yet another unit Vector is E2 which basically means that in the second element so in the second place uh the uh Vector con contains one and all the other members are zero so here you can see Zero here you can see Zero only in the second element we have one and then in the e3e what we have here is that the third element is one and all the other ones are zero so let’s actually look into uh one um bigger Vector uh in higher Dimension to make it even more sense so first I will Define and assume that we are dealing with a vector in RN so in an N dimensional space this gives me an idea that we are dealing with um so we are not dealing with nested Vector we are dealing with a simple n dimensional Vector so it has n rows and one column so using the square braces I’m going to represent my Vector so I have all these different members and members C so e let’s say it is E5 so what does this mean it means that r is equal to 5 and this I element so the fifth element is equal to 1 and all the other entries the elements in this Vector are zeros so let’s look into this is 0 0 0 0 I’m approaching the fifth element in my Vector so it’s this one this is one and the remaining all zeros so this is a unit Vector in an N dimensional space and I’m defining it by E5 because my fifth element is equal to one now those are very handy when it comes to some other uh techniques in linear algebra and just in general think about techniques like um uh row eum form solving linear equation something that we will see as part of the next unit so many things um we can do by using unit vectors unit vectors are super important so you need to understand this concept uh very well such that later on you will understand uh more advanced concepts in linear algebra so now look into the topic of sparsity in vectors so by definition the sparse Vector is characterized by having many of its entries as zero so its parity pattern indicates the position of a nonzero entries so uh what we are basically saying is that if we are dealing with a vector that contains too many zeros we are dealing with a sparse Vector so uh this sparsity pattern indicates uh also the positions of a nonzero elements so um if we have um unit Vector it means that we are already dealing with a sparse uh Vector this is a concept that is super important when it comes to linear algebra but also in general data science machine learning and AI because having a sparsity in your vector it means that you don’t have much of an information usually a value zero it means you don’t know much about that specific volum and if you got just too many of zeros and too few numbers which do um provide information it means that you are dealing with a factor that doesn’t provide you much information and there’s always a problem when it comes to data science machine learning and AI so sparcity is something that you you need to be aware of you need to know how to recognize it and you also need to know whe there’s a problem in your specific case or not so let’s look into an example let’s say we are dealing with this Vector X that has five different elements so X is a vector coming from um five dimensional space so we have for instance an element of three in the first entry then we have z z in the second and third uh entries then we have an entry um four which coincidentally also contains value four and then the last element in our five dimensional Vector X is equal to zero now what do we see here we see that the majority of elements of a vector X is equal to zero because we got in total five elements and then we got three of it actually uh being equal to zero and only two of them containing information like equal to three and four so only two elements that are not zero so nonzero elements it means that 3 / to 4 which is basically 60% 60% of all the entries in the vector X are equal to zero so the 60% it means that is above half so above 50% 60% of all the information in this Vector um the majority is simply equal to zero this type of vectors we are uh calling sparse vectors and sparsity is really important concept uh that we need to keep in mind later on so uh while we can visualize vectors in two and three dimensions in linear algebra like we just saw in case of this n dimensional vectors visualizing uh the this type of higher dimensional vectors becomes very difficult so uh this mathematical flexibility uh to work with uh this type of uh information so when we can represent uh information many with many entries we can represent it by vectors which we can actually not visualize becomes very handy for complex data structures for different simulations in physics and much more so uh we just saw in couple of examples uh how we can represent vectors in a high dimensional space using this Square braces and this common Vector notation presentation we saw that in an N dimensional space we could uh very easily represent this uh very large Matrix or vectors uh by just um using this Vector representation for instance if we got a vector that had n different entries where n is for instance thousand so let’s say we have thousand then uh we can represent uh this uh vector or this information by using common vector Vector notation so A1 A2 all the way to a th000 so of course we cannot visualize this it just doesn’t make sense we can visualize two dimensional vectors we can visualize three dimensional vectors but we cannot uh visualize thousand dimensional vectors so Vector that comes from uh r Thousand but what we can do is still make use of this very useful information in order to uh do different operations when and later on we will see that uh this property and specifically this part of linear algebra it helps us to work with vectors in any number of Dimensions whether thousands million billions this mathematical flexibility is super important for more complex data structures uh for metrix multiplications when for instance we are doing different uh algorithms including how we can represent very large matrices very large feature spaces all this different information we can represent just by making use of vectors coming from this specific uh part of linear algebra let’s now finish off this module by looking into some applications of vectors so one common application of making use of vectors is uh when we are performing different operations while having words and we want to count those words so this is a super common application of vectors and we can count these words and you can even plot a histogram of how often each of these words appear in a document so a vector of a length n for instance can represent the number of times each of these words in a dictionary of n words appears in a document so uh just for the sake of Simplicity let’s assume that we got um dictionary that contains only three words of course in reality the um dictionary what we also refer often as Corpus it contains much many uh much more many words but for the Simplicity we will assume that we just got three different words in our dictionary so that’s a total now let’s assume that we got a document uh with these different words and we want to count how many times each of those words that we got in dictionary actually appear in our document so uh if our document is described by this Vector so it contains an entry of 25 2 and zero it means that in our document we got 25 word one in our from our dictionary so in the position one 2 * word two and0 times word three so basically we have have a predetermined set of words in our dictionary in this case three words word one word two and word three and they have a specific index specific position in our vector and when we are putting these values in here then the machine or the uh computer the program will understand that if we have 25 in the first position then the word one in the dictionary appear 25 times in our document whereas the second word appeared only two times and the last word for three didn’t appeared at all so zero times in the entire document so let’s look into a practical example actually to make even more sense so um this is by the way a common practice to count different variations of a word they are common application in engrams large language models Transformers they are just a Cornerstone of many language models when we want to count the words in the document to understand how often the word appears because this gives us a idea what this document is about knowing how many time the same word appears in that uh document it gives as an indication of the topic of uh the do document also we can make use of it to do sentiment analysis to understand what this document is about not only in terms of the topic but also is it a positive is it a natural or a negative uh document so to say so uh for instance if we got uh the following words uh that correspond to our dictionary and in our dictionary we got just um let’s say six different words then what we can do is that we can say 3 2 1 let’s say 0 42 and the corresponding words are word row number horse eel and then document what this means is that we have a text what we refer as a document that contains three times the word word that contains two time the word row contains one time the word number zero times the word horse and four times the word eill and two times the word document so uh this is basically a common way representing the uh frequency of the words in the document let me actually give you uh another example and in here I want to emphasize another thing the concept of stop wordss so uh let’s say I make this 10 and then here I say there is a three times the word I two times the word uh reading two times the word library four times the word book zero times the word shower and 10 times the word uh so uh you can see a that in here we are dealing with a document that contains 10 times the word uh which is what something that we refer as a stop word so those are things that actually don’t give us too much information about what the document is about because uh is just used everywhere but it is appearing too often so you can see 10 times the most frequently appearing word this is what we refer as a toop word and then another thing that we can observe the second thing we can observe is that we are dealing most likely with a document that describes library reading uh because you see the words like reading you see the word like book library but another word shower that is totally unrelated to reading book or library is appearing zero times so even by looking at disc counts we can already get an idea what a topic of this document is about out so uh you can see already now from this very basic example where I made too many assumptions regarding how small the uh dictionary should be uh you can even see now how we can use this counts in our dictionary from our text in order to get idea about the topic of the document or topic of the conversation it can be topic of the uh tweets if you have a tweet data it can be topic uh regarding book if you have many book um uh book texts it can be for instance the topic of the review if you got uh product reviews from uh Amazon for instance using discount can help you to get a topic regarding topic from that text then you can also use it to remove the stop words because usually the stop words are the most frequently Pi words it can also give you an idea about the sentiment for instance here we are dealing with natural sentiment it’s not positive it’s not negative it’s just reading a book in library that kind of topic so all this can be super helpful when it comes to natural language for processing that’s a field where this uh text processing text cing and then using that for modeling purposes is what uh what plays a central role it also plays a super important role in the large language models in the Transformer models and uh in simple matters like uh B of words or uh in the uh tfidf all these they are based on this idea of counting words and how we can use this information and you can see how vectors come into play in these different applications of linear algebra in data science natural language processing in artificial intelligence in machine learning so they are super important another application of vectors can be representing customer purchases for example an N Vector P so let’s say p can record a customer purchases over time with pi being the quantity or dollar value of an item I now what does this mean so let’s say we have Vector P that represents the customer’s purchases and we are dealing with a single customer and we are just saving over time that information how many times customer has made purchases over time so the quantity is in the um dollars so the dollar value of item I purchase so we are basically keeping track of uh what is the value of the item I that the customer has purchased so what we can do is we can assume that in here actually it already makes that assumption it says n Vector which means that the number of rows or number of um items that the customer purchases is n now what the um the problem says that it represents is that in each entry and here we have in total n entries we got a dollar value of item I which means that here if I have P1 P2 all the way to PN and here somewhere in the middle I got Pi I in the East position it means Pi represents the value of item I so for example if I’m dealing with a CER that buys um let’s say uh cores and uh the first item that the customer is buying is a mathematics course so I’m writing mathematics course and this is the first course that it buys e is by the way just a um way to refer to the E purchase so let’s say um here somewhere in the middle the um customer decides to buy a deep learning course deep learning learning course and then it continues buying uh the customer continues buying courses and the last course that the customer buys is let’s say um career coaching course now let’s say the mathematics course cost uh around $1,000 let’s say the uh deep learning course costs $3,000 and then let’s say the career coaching service which is usually one of the most applied and personalized one can cost all the way to $5,000 now we see that in the East position this is the East position let me change the color by the way so let’s say this is the East position this is the first position and this is the last position so those are just indices we can see that in the East position we got the 3,000 which means that the p e is equal to $3,000 so this indicates that in the East purchase the customer purchased deep learning course and the value of that item was equal to $3,000 all right so now we are ready to go on to next major topic which is about vector addition and subtraction so we are going to do some operations and apply this operations to vectors so let’s first formulate Define this ideal of vector addition so uh two vectors of the same size are added by adding their corresponding elements the result is a vector of the same size so uh let’s unpack this it says two vectors of the same size are added by their corresponding elements so here it refers to two different vectors let’s say vector v and Vector W and it says let’s add them what we refer as vector addition and says for that what we need to do is to take all the elements of v and then all the elements of w and using their corresponding elements so indices that helps us to understand where those elements are located we are using in order to add each element in the vector v to the element of the vector W in the same position and do note that in the second part it says the result is a vector of the same size because we are adding two different vectors of the same size mentioning here it means if we add two different vectors to the same uh that have the same size we are going to end up with a vector that has the same size now once I go into the examples it will make much more sense let’s quickly also look into this concept of substraction so on its own uh subtraction is very similar to this idea of addition so if we have a substraction let’s say we have vector v We substract Vector W then we are doing basically uh what we just did to the addition only instead of doing add we are doing subtract so again we are just uh we are just substracting from vector v Vector W they have the same size so we end up having the result uh which is a vector of the same size only one thing that you can see is that this can be also Rew written as V Vector plus and then minus W so we basically can represent substraction um on its own as a way of adding only we take the negative so the um opposite directed Vector so this will make even much more sense uh once we go on to the examples so let’s look into our first operation example where we are adding two different vectors this a basic example we got just two dimensional two vectors we got Vector a that has entries 2 three and Vector B that has entries 1 4 and what we are doing is is that we are adding Vector a to Vector B we just learned that a we need to have the same size of vectors so you can see that Vector a has a dimension 2 by one vector B has a dimension of 2 by one so their sizes is the same both they got two entries only two elements and at the same time we just learned that what we need to do is to take their corresponding elements and add them to each other now what does this mean it means that we take from a the first element two and then we take the first element of the second Vector which is the B so we take the two from here and one from here the first element of a and the first element of B and then we are adding them to each other 2 + 1 is equal to tree and then the same holds for the second ENT tree so tree which is the second element of vector a and then 4 which is the second element of vector B we are saying 3 + 4 is = to 7 so let me write it down even in a simpler manner such that it will make much more sense so Vector a has elements 2 three in the first element we got two in the second element we got three so a then we want to add B which has in the first element element equal to one and the second element is equal to four this means that if we want to add these vectors 2 3 + 1 4 this is equal to we need to take two we need to add one so this element and this element and then we need to take three we need to add to four so this one and this one which is equal to 2 + 1 is equal to 3 3 + 4 is equal to 7 so we got uh Vector 37 do note that this Vector the result vector contains again two elements and just one column so 2 by 1 so you notice that the sign that the size is the same of this result Vector now let’s actually generalize this concept before moving on to the next example so if we got let’s say Vector a that contains n elements A1 A2 all the way down to a n and it is from n dimensional space and we got Vector B that also has n elements so remember that they both need to have the same size so B1 B2 all the way to b n so they come also so B comes also from n dimensional space so then when we add a to B this is equal to A1 A2 all the way to a n plus B1 B2 all the way to BN so n by one n by one the sizes this is equal to let me actually use this color to make it even more visible so I for the first entry for my result factor I will get A1 Plus B1 then A2 + B2 so all the way down onto the end element which is a n plus then we is a different color A1 B1 B2 b n so you can notice now in general terms what we are doing here so we are taking the A1 coming from the vector a we are adding in the same uh position the value that comes from Vector B which is B1 we are saying take the A1 Plus B1 this is the uh first element so the position stays the same and then in the result Vector so we take all the corresponding values that are have the same position in the corresponding Vector first from Vector a and then Vector B we are adding them and this forms our new vector and this new Vector will again have a size n by one so you can see that a the sizes of the two vectors are the same both have n elements and then we are using their corresponding elements to add them to each other element wise and then we are getting the result that has the same size so n by 1 so this is a more General description of how you can add two vectors let’s now look into this specific example so we have a vector with the entry 073 so this comes from R3 you can see so three dimensional vectors the second Vector is 1 2 0 and then the final result is 1 193 so how we got this we took Zer we added 1 seven we added two and then three we added zero so you can see all these elements element wise and then this is equal to 0 + 1 is 1 7 + 2 is 9 and then 3 + 0 is 3 exactly what we got here so again the same sizes and the result is from the same size so quite straight for forward now when it comes to the vector substruction what are we doing that um so what are we doing here so we are doing kind of very similar thing we are taking this element one we are subtracting the other one in this first element then we are taking the nine in the second position and subtracting this again from the second position of the second vector and we are putting in here 1 and then 1 – 1 is equal to0 0 9 y – 1 is = to 8 so we get result Factor 08 like in here and you can see that the sizes stay the same so also in this case let’s write more General um this ideal subtraction if we got a vector a from RN so n dimensional space and it can be represented by A1 A2 all the way down to a n so it has n elements n by one and then we got B also from RN so coming from the uh n dimensional space which means that it got n elements so B1 B2 all the way down to BN again with the same size n by one then a minus B is simply equal to a A1 let me actually show use the same colors to make it easier to follow so let me first draw my Square races and then here I will use blue for a and then red for the uh color for second Vector which is B here I will use black minus then given that the same size should be for the result Vector I already know that I expect n different elements for this and then here I’m taking this first element that comes from Vector a i subtracting from this the first element that comes from Vector B so element wise substraction B1 and I’m already getting the result for the first element in my result Vector so you can see A1 minus B1 I’m taking this element and this element as subtracting them from each other to get A1 minus B1 and then the same holds for all the other values only coming from different elements from Vector a sub substracting from this the corresponding values element Wise from the vector B so B2 B3 all the way to a n so you can see that in my result Vector a vector minus B Vector in the first element I get A1 minus B1 then A2 – B2 then A3 – B3 in the third element all the way down to the end element which is equal to oh this should be b a n minus BN so um this already should makes uh much more sense so every time we take the element in the same position from one vector than the other we subtract from each other in order to get the corresponding element in the final Vector all right so let’s now uh before moving on to the properties um I wanted to show you um this only in a coordinate space so what this means in terms of visualization in a coordinate space so uh let’s say we have a coordinate space this is my Y axis this is my x-axis so this is X and the Y and this is my Center so 0 0 and what I’m doing here is simply I want to have Vector a let’s say this is just um Vector a simple one with the coordinates um let’s say four and – 2 and I got Vector B let me use a different color Vector B that has coordinates let’s say minus 4 and four so let’s actually visualize them let’s first start with the vector a uh which has a x value four three and 4 1 2 3 and 4 and the Y value minus 2 so this is my Vector a and let’s now visualize the vector B so Min – 4 and four which means that let me actually extend this this is min -4 so the x coordinate is min -4 so it should be here and then the y coordinate is four so 1 2 3 and 4 it’s this one which means that my Vector B is this one all right so you can see now that the vector a is in here and the vector B is in here now what I want to do is to add this two vectors to each other so what I want to do is to take this Vector a and add to this the vector B which is is equal to 4 – 4 it was 0 and then – 2 + 4 is = to 2 so zero and then two it is zero and two two so this is my result Vector so now when we are clear on how we can add vectors how we can perform these different operations and what it means in practice when it comes to looking at the vectors in a coordi space and adding them or subtracting them we are ready to look into the properties of vector additions so this is something that will definitely seem familiar to you uh from pre-algebra where we are basically using all these properties that we already know that holds for uh numeric values for the scalers that being transferred to this Vector space so we are going to talk about this four different properties that a vectors uh have the first one is the cumulative property which says that if we add a vector a to Vector B then this is the same as adding a vector B to Vector a so basically the order of the vectors doesn’t really matter when it comes down to adding them so formally a plus b is equal to B+ a for any vectors A and B of the same size then we have associative property which says a plus b + C is equal to a + b + C we can write both as a + b plus C now what does this mean we know from prealgebra that this parenthesis me means first do this addition and then do the rest of operations in here it basically says if you add a to the B first and then you add the C is the same as first you add B to the C and then on the top of that you add the vector a so then the third property is addition of zero vectors which says if we add a zero Vector to Vector a then this is equal to adding a vector 0 to a and this is equal to Vector a so adding the zero Vector has basically no impact on the vector whatsoever then the final property is subtracting a vector from itself which means if we take the vector we substract the same Vector from itself so a minus a and we get a zero Vector so a minus a is equal to Zer vector and this heals the zero Vector now let’s look into each of those properties one by one and Let’s uh look into specific examples uh in some cases we will prove this on the example that we have to make this Concepts much more clear so let’s start with this cumulative property of vector additions so we want to see whether a plus b is equal to B + a so let’s say we have a vector a that has coordinates or magnitude and direction that is equal to one one and two then we have a vector uh let’s say B that has a magnitude and direction of Min – 2 and three so the first thing that we want to check is indeed whether the A + B is equal to B + a so therefore let’s first calculate this part and then we will calculate this part that I will def by one and two and we will see whether we are indeed having the same value the same vector or not so let’s see so we have here a so a plus b which is the first value that we want to calculate a + b is = to 1 2+ – 2 3 and we learned before that this is simply equal to take this value and then add this one so 1 + – 2 and then 2 + 3 so this gives us a vector 1 – 2 is = – 1 and 2 + 3 is = 5 so we get that A + B is = -15 this Vector now let’s look at the second quantity so B Vector B plus Vector a this is equal to – 2 3 + 1 2 and this is equal to – 2 + 1 and then 3 + 2 this gives us – 2 + 1 is = to min-1 and 3 + 2 is equal to 5 so we can already see from here that the quantity 1 is indeed equal to quantity 2 which proves that indeed the A + B is equal to B + a what this basically means is that adding two different VOR the direction or the order is not important whether you add a on the top of the b or B to a it doesn’t matter at the end is the same and actually you can also see it if you uh combine this or if you do this in a more general terms so let’s say if we have a vector a which is equal to in an N dimensional space A1 A2 up to a n so it has n by one dimension and you have a vector B with the same size from the same RN Dimension and it has elements B1 B2 up to BN and the dimension is equal to n by one then if we calculate first a plus b and this is equal to Simply A1 + B1 A2 + B2 up to a + BN and if you calculate the second U amount which is B + a and this is equal to B1 + A1 B2 + A2 up to BN + a n you can see that A1 + B1 is equal to B1 + A1 simply from pre-algebra you know that if those are constants for instance 2 + 3 is = to 3 + 2 in the same way a 2 + B2 is = to B2 plus A2 and then here up to a n plus BN is equal to BN + a n what this means is that all these elements they are basically the same which means that we already have a proof so we get this proof and we can see that even for the general term independent what is Vector a is what this Vector B is that a + b is equal to B + a this is exactly what we saw before in the first property which is called commutative property of the vectors that A+ B is equal to B + a now let’s move on to the other property which is called associative property of the vectors now what this property does and says is that a plus b so first we do this plus C is equal to a + b + C and this is then equal to a + b + C now let’s then see um this specific property on an actual example so what this basically says is that if we have this example where a is equal to actually I had this before let me simply just remove this part let’s then add our third vector which is C and let’s call it let’s say it has a representation of four and five then the idea behind this property is that what we need to prove here that A + B within the parentheses plus C is equal to a plus B+ C and then this is equal to a + b plus C so let’s see actually whether this is indeed true for this specific case now this should come very intuitive so I’m going to do it very quickly so first we have this quantity this one then we have this one and the third one let’s do it very quickly so so A + B + C is equal to one two plus and then we have C so it is simply 4 five and then this is equal to we saw before when doing this that we were getting one Min – 2 2 + 3 and then we add this four five this is simply equal 2 1 – 2 is -1 and 2 + 3 is 5 + 4 5 now given that it doesn’t really matter no longer that do we have uh here parenthesis or not this basically means that this volue is simply equal to -1 + 4 so here -1 + 4 here 5 + 5 so this is then equal to three and then 10 all right let’s then now quickly do the second amount which says first add the vector B to Vector C and only then add the vector a on the top what this means is that we need to take one two this is Vector a and we will only add this once we have added the minus 23 the vector B plus to the vector 4 five okay so we can see that we are just leaving this in here let’s first add this two – 2 + 4 3 + 5 so this gives us 1 2 + – 2 + 4 is two and then 3 + 5 is 8 so this gives us let me remove this calculations so this gives us 1 + 2 is = to three and then 2 + 8 is = to 10 okay great so now we got already the quantity one being equal to quantity 2 let’s check whether this is all equal to this one it should already be um something that you see now given that um we know just from mathematics that parenthesis doesn’t really matter when it comes to the scalers and adding two vectors is basically very close to this idea of edited property um of the edited property of the scalers but just let’s quickly do to be 100% sure so when we take this Vector a to the B and to the C we had all this this is equal two want to added to minus 2 three and then added this to four and five now what this is equal to let me actually write this in be sure to way such that it can be all fitting in the small place so one cu plusus 2 3 + 45 this is equal to basically 1 – 2 + 4 and then 2 + 3 + 5 and what is this number 1 – 2 + 4 is simply equal to 1 – 2 is = to -1 and then + 4 is = to 3 so first element is 3 2 + 3 + + 5 is equal to 5 + 5 which is equal 10 perfect so now we get the confirmation that indeed A + B + C is equal to a + b + C is equal to a + b + C so let’s quickly also look into this addition of zero vector and the subtracting a vector from itself properties and uh the detailed explanation of this or example of this I will leave it to you so when it comes to this a plus um 0 is equal to 0 + a is equal to a so this property let’s say if a is equal to this 23 and then we are adding on this a plus some zero Vector which basically means take two threee and then added the same size of zero Vector you can see that this is the same as adding this zeros on these values now what do we get we get add that this is equal to 2 + 0 is 2 and then 3 + 0 is 3 there we go so we already see very quickly that it doesn’t really matter whether we add a zero Vector to this original a vector or not we in all cases it just adding a zero Vector has no effect and seeing from the commutative property that a plus b is equal to B+ a we already know that if um a + 0 is equal to uh a and is equal to this then also 0 + a will be the same and we can see indeed that we just saw that a + 0 is simply equal to a so we basically have quickly proven all this now when it comes to the subtracting a vector from itself I think this is a very nice one just to see how we um uh take the same Vector I subtract from that value and we get zero and this is very similar to working with just real number numbers in the same way as 3 – 3 is equal to Z also when we have a vector consisting of the scalers like a is equal 2 23 in the same manner if we take this a and we subtract it from itself so a minus a then what we will get is 23 minus 23 and this will give us 2 – 2 is0 and then 3 – 3 is z so we get Vector zero so zero vector so now when we are clear on how we can perform different operations on our vectors and also we know uh what are the properties of uh adding and subtracting uh different vectors we are ready to move on to a bit more advaned topics so uh in this module we are going to discuss this idea of scalar multiplication we’re going to look into the example how what happens and how we can do the uh Vector multiplication with the scalar then we are going to uh look into the span of vectors what it means to have a span of vectors uh what is this IDE of linear combination and the relationship between the span and linear combination and the unit vectors now we are going to look into the application of scalar Vector multiplication in audio scaling uh example and then finally we are going to finish off this module by looking into the length of a vector and a DOT product and we are going to uh go back to this idea of distance understanding vector magnitude and understanding Vector length so let’s get started now before we look into this idea of span and linear combination I quickly wanted to look into this idea of scalar multiplication and the um specific definition of it so formally the scalar multiplication involves multiplying each component of a vector by scalar value effectively scaling the vector’s magnitude so what do I mean here let’s say we have a vector and I will write it in the general terms to keep everything General so let’s say we have a vector a let me pick up my pen a and this Vector a is from n dimensional space so it is from RN and it can be represented by A1 A2 up to a n and I have this magnitude um of a vector and now I want to scale this Vector for which I know the magnitude and the direction I want to scale it with a scaler and we learned before that the scaler is just a number so um scaler in this case I will be uh referring it to uh by C so c will be my scalar and uh this comes from R which means that it’s a real number let me actually use a different col color to make it easier to follow okay so my scaler will be with the color uh red so C and C comes from R so what do I mean by scalar multiplication I mean that I want to find what is this c times a this is what we mean by scaler multiplying with Vector now what does this definition say it says when we are multiplying scalar with Vector so the scalar multiplication meaning multiplying Vector with the scalar it involves multiplying each component of a vector by a scalar value so if we translate it to this specific example it means that this amount so this amount is equal to taking C and multiplying it with each element of this Vector so each component of a vector and what are the components of my Vector the A1 A2 a up to the point of a end so all these components so that means that the first element of this new Vector the scalar multiplication a result will be C * A1 C * A2 dot dot dot so all this middle elements and at the end again c times and then a n and then in both cases of course the number of elements doesn’t change so the so the number of rows of my Vector doesn’t change it’s n so here also n and then number of columns is the same so it’s just a column Vector so one column so what we see here is that we go from A1 to C * A1 we go from A2 to C C * A2 up to the a n transforms into C * a n so we see very easily that I keep all the elements from this Vector I take them in here and instead what I’m doing is that I’m multiplying every element from this vector by the scaler C so this is exactly what this definition says and let’s actually go ahead and do a Hands-On example with some real numbers to have this um method and to have this uh definition very clear in our mind because we are going to make use of this fundamental operation scalar multiplication on and on in the upcoming lectures and just in General in your journey in any applied sciences so this is an example of scalar multiplication uh here what we are doing is that we want to multiply this Vector C so in this case the vector is defined by a letter C and then on the top we can see the arrow indicating that this is the vector now and here we refer the scalar by a letter K we are saying we want to perform scalar multiplication which means that we want to multiply the uh Vector C by the scalar K so how we can do that so what we want is to multiply K by C and we just learned that for that what we need to do let me write this over so this equal to minus 2 multiplied by 4 – 3 this is my Vector so this is the k a and this is the C this is equal 2 so I take my scaler and I multiply it with the each of the element of the C so – 2 * 4 and then -2 * -3 so – 2 * 4 is = to – 8 and then – 2 * – 3 so– it goes away it becomes a plus and the 2 * 3 is 6 so my end result the K * C is equal to – 8 6 this is my final result so let’s quickly also do yet another example and this one is a unique one because it’s relating to this idea of U multiplying something with a zero uh which is something that we also uh know from our high school that when we multiply number let’s say seven by zero we’re getting zero and here in this example exle the uh problem is describe the effect of a scalar multiplication by zero on any Vector which means what we are doing is that in this example is we want to know what is this result of any Vector let’s say Vector uh C so we will use the same example C only this time instead of multiplying it with the scalar K = to minus 2 our scalar will be zero which means that c is equal to 4 – 3 and then K is now equal to zero and we want to find out what is this K * C let me actually write down the K with a different color k is equal to zero so what we want to find out is K times and then C and this is that equal to zero so I’m taking the K 0 times then I’m taking each of the elements of C which is four and then minus 3 and I know that when multiplying the number with a zero it gives me zero which means that I end up with 0 here 0 * 4 is 0 0 * – 3 is also zero so I end up with a zero Vector now this gives me an idea already that I can make a general conclusion that independent of the type of vector that I have independent what are these values in my C uh if I have any Vector C and I’m multiplying it with zero then this will always give me a vector of zero because all the members of this final Vector will be just zeros so if for instance the C comes from uh let’s say r n so it has n different elements it comes from uh n dimensional space then my final result of 0 time C so this zero Vector this one so zero that this one will come also from our end so you will be having a vector so zero time c will then be equal to 0 0 blah blah blah blah zero so n time zeros so this is then the idea of multiplying so scaling a vector with zero and this is our example two all right so let’s now move on on to our application of scalar Vector multiplication and then after this we will go back to this idea of linear combination and dispense so in this specific application we have a scalar Vector multiplication and we are looking into application of audio scaling so the scalar Vector multiplication audio processing uh this can change the volume for instance of an audio signal without altering its content so um you might have noticed that um when uh when you are listening to video you can simply increase the volume of that video or decrease it but you will notice that the content doesn’t change you are just increasing the volume or decreasing it even on the TV when you are watching a show you are increasing The Voice or decreasing now what you’re basically doing behind and this is super interesting is that behind the scenes what is happening is that there is simply um audio that um contains that show and audio of that show is being multiplied with a scaler and that scale is simply the volume scale if you scale it in such way that you want to decrease the volume so the audio will then have a lower volume then you are simply multiplying it uh your vector containing the audio information in such way that those newer volume indications they will be they will be containing lower numbers hope this makes sense let’s look into the example this make uh this will definitely clear this out so um let’s let assume we have an a vector a that represents the audio signal and we want to multiply Vector a by scalar B to adjust the volume so B is some sort of number it can be so B comes from our so is a real number while a is simply a vector given that it doesn’t mention it here I’m assuming that a comes from RN so it comes from our uh n dimensional space so imagine of a as this Vector A1 HQ blah blah blah blah up to a n and each of these values it basically describes uh an uh the audio signal so it represents um uh an amount so it contains an amount that represents the audio signal of your uh video or uh your uh show and then the B in this case for instance in this example you can see that the B is then uh equal to for instance 1.2 1id 2 or B is equal to Min – 1 / 2 so you can see that b is equal to 1 / 2 which basically is offensive saying that b is equal to 0.5 or B can be equal to min-1 / 2 which is – 0.5 now then it says then the B * a which basically means multiplying our um scalar beta by the vector containing the audio signal a so this B * a is perceived as the same audio signal but at the lower volume now why lower because you can see that b is equal to 0.5 or minus 0.5 it means that once you take all these elements of your a and you multiply it with a number that is smaller than one in this case 0.5 then all these numbers will decrease which means that also your audio volume will decrease so let me actually uh show you an example so let’s say our talk show is very short and you know the audio variation is very low you have a vector a that is quite small it comes comes from a three dimensional space so R three and it has numbers like three uh six and then five so 3x one vector and then we have our audio adjustment scaler beta which is equal to 0.5 now when we take the beta we’re multiply it by our audio signal then what we do times this clear so times what we are doing is that we are simply taking all the elements of our a so Three 6 and 5 and what we are doing is that we are multiplying it by 0.5 0.5 and 0.5 or you can also say 1 / 2 so what this is equal is that 3 * 0.5 is 1.5 6 * 0.5 is 3 and then 5 * 0.5 is 2 2.5 and you can see that all these numbers 1.5 3 and 2.5 they are smaller and specifically two times less than all the original values in the um original audio so original audio is a which was 3 6 and 5 and the new audio the scaled one is so audio scaled so B * a is equal to 1.5 3 and 2.5 so you can clearly see this transformation where uh this element three is larger than 1.5 6 is larger than three and then the last element five is larger than 2.5 which means that this audio audio is much at a higher volume so the Volume Two Times Higher then this audio so this is basically the idea of uh applying scalar multiplication to our audio preprocessing I will leave the other example to you that will show that when your scaler is equal to minus 0.5 you again will end up with a lower volume only that time the volume will be much much lower than the original one so now that we know how we can perform scal multiplication in theory as well as we have looked into an example how we can do it in terms of the numbers and multiplying them and we have also seen uh applying scale multiplication in practice uh so we have seen in this audio processing stage the uh multiplication process we are ready to look into the visualization of it this will help us to get a better understanding on uh what exactly happens when we are scaling different vectors let’s look actually in the following example so let’s assume we have a vector oh let me remove that so let’s us show we have a vector and that Vector is let me get a color this one for instance a vector a and this Vector a consists of elements one and two so where does this Vector like the vector is with um one so here in our coordinate system this is our xaxis this is our y AIS and here we got uh let me actually pick another color let’s say black one and then we got one and then two right this is two this is one so it is this one so the line that we get here it is this one so this is our Vector a now let’s assume I want to multiply my Vector a so I want to scale my Vector a by a constant Tree by scaler tree so I have a scaler let’s say I call K and this k a different number let’s say k is equal to three so what I want you to do is to perform a scale multiplication so I want to obtain K multiplied by a and we learned that this is simply equal two three times and then one two and then this is equal to 3 * 1 3 * 2 which is equal to 3 and then six so let’s also visualize the scaled uh Vector so let me pick this yellow color this will be our scaled Vector so we have that scale multiplication and we are going to visualize that so we have three and six so this is three one 2 three and this is six so we have this point so you should already see what is going on here so we got 3 a here so you can see that this part is our Vector a and this longer one is 3 a and even visually you can see that this longer Vector is simply the three times of the shorter Vector so we got this and then if you add on the top of this the same three times you will then end up with the original so scaled version of that so basically this is a this is a this is a we combine three different so we scale a three times and we simply get a three * longer version with the same direction so you can see that when we are scaling even visually it makes sense so we are scaling our Vector a three times and we are just getting that Vector so we are transforming well let me remove this so basically we are taking this vector and we are scaling it up to this point if I would do it on only two times then it would be something like this or one and a half times it would be something like this so only half of it so now this should make much more sense let us actually do yet another example to uh make sure that we are clear on this visualizations because we are going to make use of it when uh looking into this idea of linear comp combination in a spin so let’s say we have a vector B and this Vector B has elements Z and three so let’s visualize and uh plot this Vector so it contains elements Z and Zer and three so0 and three so this is the X element and the Y element on the Y AIS we can see this is three which means that our Vector B is this vector all right perfect so this is our B let’s now multiply so scale our Vector B by scalar 2 so let’s say we want to get 2 * B so what is this amount this is equal to 2 * 2 * and I’m simply taking each of those elements zero and then three so this is then equal to 2 * 0 is 0 and then 2 * 3 is equal to 6 so this is my new skilled Vector 2 * B Vector this one so let’s visualize this the x-axis value is zero so we are still here and then the Y AIS value is sixth so what is sixth this thing all right so you already should see that this is very similar what we had before so this is 2 B all right so this all uh should make sense uh also we learn as part of the um High School when visualizing different plots so this is quite similar to this idea of having Y is equal to X and then scaling it getting like Y is equal to 2x so in this case only we know exactly where the vector starts and ends uh so we have uh much more specific definition instead of having all this infinite number of points on the line but the idea stays the same so we are taking this vector and we are then scaling it two times so we get 2 B vector and I could do the same only instead what I could also do is I could do like uh 0.5 or 1 / 2 * B so I take the half of it which means I would get this vector or I could multiply with minus one so minus – 1 * B so I will scale with minus one and then I will simply get the negative version of my original Vector so this thing this would be minus b or min-1 * B so this is basically the idea of uh scal multiplication when visualizing it in our coordinate system cartisian coordinate system and now when we know all this we are ready to move on on this idea of linear combination and now when we know all this we are ready to move on on this idea of linear combination so let’s now formally Define this ideal of linear combinations a linear combination of vectors A1 up to a m using scalers B1 up to BM or what we also refer as beta 1 to Beta m is the vector beta 1 * A1 Plus up to Beta M * a m and the scalers are called the coefficients of linear combination and any Vector B in N Dimensions can be expressed as a linear combination of the standard unit vectors E1 up to n the coefficient in this combination are then the entries of B itself well this is whole bunch of information uh let’s unpack them one by one firstly um I want to mention about this m so far we have seen this idea of n so I just wanted to experiment with a different one just to ensure that we are clear that you can use any source of identifier to describe the size of your um uh number of vectors that you got and uh in this case we got M different vectors because so far we were using this n in order to describe the size of a vector and now we are no longer talking about the size of a vector but the number of vectors therefore I specifically didn’t use the letter N so here m is simply the number of vectors so don’t confuse this with this thing where we were plotting this and we were saying this A1 A2 up to a n because in here we basically mean that we are dealing with some Vector a and this has n different elements whereas in here we are already moving from this IDE of one vector and now we are talking about multiple vectors so we have M different vectors they all look like kind of this only with bit more complex indexing that we also saw before all right but we will learn this um that’s not an issue I just wanted to mention this to ensure we are at the same page so then let’s move on to this idea of using scalers beta 1 till beta M so it’s a common uh practice in linear algebra in just in general in mathematics but also definitely in data science statistics and in artificial intelligence to use beta 1 as a way to describe the coefficient so what do you mean by coefficient it is just a scaler so it’s just a constant or number so in this case for instance this beta one can be 0.5 beta one can be uh two beta one can be let’s say 100 it just describes how much we are multiplying scaling this Vector A1 so so far we have done lot of scaler multiplication already a lot of details there and we have seen different times different scalers that we use we can use um zero as a scal we can use any other number as long as it’s a real number so this beta 1 should belong uh in the real number space so it’s a real number and of course the same holds for uh all the other betas so we have M different vectors which means we are going to have M different scalers because each of those vectors we are going to multiply with their corresponding or respective scalers so beta 1 is basically the scaler uh or the um uh coefficient that we are using to scale A1 maybe I can actually write this down on a new page such that we can save this as a slight page for you let’s write it down so what do we have as this idea of linear combination so a linear combination simply involves taking several vectors uh to go from this uh formal definition to more practical uh terms so we got this A1 A2 up to am and what we want to do is to take the linear combination of this m different vectors so we got m is the number of vectors and to get a linear combination we need to uh scale each of those vectors which means that we need to have these different scalers let’s say beta 1 for A1 and then plus beta 2 for A2 so each time we are scaling each of those vectors where beta 1 is the uh scalar or the coefficient of the vector A1 and we are multiplying we are performing scalar multiplication of our scalar beta 1 with the vector A1 and then we are adding to this our beta 2 which is the coefficient corresponding to the vector A2 and then adding beta Tre times A3 and then dot dot dot so all these different uh vectors up to the point of beta M time a m and all this so A1 A2 up to a m those are all vectors belonging to the m space so those are all vectors coming from the um m diamension space so um in here this is the linear combination of our M different vectors and the uh beta 1 beta 2 up to Beta M those are all constants so those are scalers or real numbers that belong to R so those are real numbers all right so now when we are clear on that let’s also unpack this idea of coefficients so the scalers are called the coefficients of linear combination so basically all this members so beta 1 beta 2 of two beta M that belong to real number space they are called coefficients this is what we are referring as coefficients and this coefficients this ID and the name is super important because you will see this time and time again appearing in your uh very basic machine learning models or some other applications of linear algebra because the end goal is always to find these coefficients so this coefficients those are numbers that we are using to scale these different vectors and uh the idea of coefficients is very Central because those are numbers that Define how exactly we are combining all these different vectors because this beta 1 beta 2 Beta 3 they can be different numbers real numbers and every time when we are choosing these coefficients or these betas we will then end up with a different combination of these vectors so we’re basically mixing all these vectors and the way we mix it and how we will mix it it will depend on the values of this beta 1 beta 2 Beta 3 up to Beta M so these coefficients so therefore coefficients are super important and they Define the end results from our linear combination so any Vector B in N Dimensions can be expressed as a linear combination of a standard unit vectors E1 up to e n so when looking into this um idea of unit vectors uh we saw already what this E1 is what is E2 is up to e n and we saw that E1 is for instance if it’s from an N dimensional space and it says from n dimensions then E1 simply means 1 0 0 do dot do do0 then E2 means 0 1 0 dot dot dot dot zero so we already saw this this is not something new that we are seeing so 0 0 blah blah blah and then one at the end and what this definition basically says is that any Vector b as long as the B comes from n dimensional space we can represent this by using this uh unit vectors and by linearly combining them so this is get another part of this definition and we are going to by the way um go through each of the parts of this definition one by one going through each of their examples as well as visualizing them so now I just want to quickly unpack all the parts in this definition before moving on to step bystep examples and explanation so this is about this linear combination of any n dimensional uh Vector B that we can uh create by using a link combination of these unit vectors I will come to this in a bit so then the final part of this definition is that the coefficients in this combination are the entries of B itself so it says that the coefficients so beta 1 up to Beta m in this linear combination that we can create are the entries of B itself so we will come to this section once we are done with the first part so first let’s have a good understanding of what this linear combination is and we will also touch base and we will also formally Define the idea of span and after that we will move on on uh representing and expressing any Vector B in N dimensional Space by using standard unit vectors E1 up to e n and this idea of coefficients and then entries of B so let’s start with the first one so let’s assume we have two different vectors we have Vector a and this Vector a is equal to one 2 so let’s plot this one and two in our coordinate space that is this one which means that our Vector a is this one and let’s assume that we have a vector B and this Vector B is equal to 03 so 0 is here and then three is here which means that our Vector B is this one this is Vector B now I want to create a linear combination of this Vector a and Vector B so we just learned from the formal definition that in order to do so I need a beta 1 to multiply the vector a and then I need beta 2 which is the coefficient corresponding to to my second Vector in order to multiply the second vector which is B Vector B okay so I’m getting the linear combination of A and B by taking any beta 1 and beta 2 which are real numbers so beta 1 and beta 2 belong to R so they are real numbers and then I’m getting a linear combination of the two so let’s look into a few examples of a linear combination of vector A and B dependent on the different choice of the co efficients like beta 1 and beta 2 so example one is that beta 1 is equal to zero and then beta 2 is equal to Z Now what is the linear combination of A and B when my coefficient beta 1 and beta 2 both are zero it just means that I’m getting 0 times a plus 0 * B which is of course 0 * 1 0 * 2 plus and then multiplying Vector B with a scaler 0 which is 0 * 0 0 * 3 so let’s quickly do this what this value is this is equal to 0 * 1 is 0 0 * 2 is 0 0 * 0 is equal to 0 0 * 3 is equal to 0 and this is then equal to 0 + 0 0 0 + 0 is 0 so I’m basically getting a vector zero all right so this is then equal to zero so this equal to Vector is zero so I can also say that this vector or it’s actually a point so this point is simply a linear combination of these two vectors now this is super basic case let’s look at another case when our in our second example the beta 1 and beta 2 so our coefficients they are actually not zero there are some other nonzero real numbers so in this example I will then take beta 1 = to 3 and then beta 2 is equal to two and then what I will do is that I will take actually I will take the um minus 2 then I can also get rid of one of the elements and I can get actually a zero for one of the elements I will show you in a bit so then the linear combination of A and B using this coefficients beta 1 and beta 2 where beta 1 is equal to 3 and beta 2 is equal to minus 2 is then equal to so this amount this amount is equal to 3 * 1 2 and then plus we got – 2 times 0 and three now what does this give us 3 * 1 is = 3 3 * 2 is = 6 Plus and then – 2 * 0 is = to 0 and then – 2 * 3 is = to – 6 so you might have already noticed why I picked the beta to equal to minus 2 I wanted these two numbers to actually cancel each other so you see because 6 + – 6 is equal to Z so what do I get in my final result as a linear combination of these two vectors I get 3 + 0 so 3 + 0 so 3 + 0 and then 6 + – 6 and this gives me 3 + 0 is 3 6 + – 6 is 0 there we go so this is my linear combination of the vector A and B when using the coefficients equal to 3 and minus 2 respectively so this value is actually equal to three and zero in this case all right so let me actually clean this up because I also want to visualize this idea and then we will go uh back to this uh linear combination let’s just summarize uh what we got before moving on to the plotting part so if we simply take a and we add to this B so this is the first case so this is as you might have already guess this is also linear combination here we are saying take 1 * a and take a 1 * B and this is yet in our linear combination here the beta 1 is equal to 1 and then beta 2 is equal to 1 so this linear combination gives us a vector that is 1 + 0 is = to 1 and then 2 + 3 is = 5 this is our first linear combination when the beta 1 and beta 2 is equal to 1 this is a basic case so doesn’t require too much explanation here we have seen already this let’s now look into the other example that we saw when we use uh the zeros as our coefficient so that is 0 * a + 0 * B then this gave us 0 0 this was our second linear combination when beta 1 and beta 2 were both equal to zero and then the third linear combination that we saw was that 3 * A+ – 2 * B this gave us three and zero this was our third linear combination where beta one was three and then beta 2 was minus 2 so so then the linear combination of these two vectors is basically all the possible combinations of these two vectors that I can get when scaling or when multiplying these two different vectors by different sorts of uh vector by different sorts of scalers so in all these different cases what I’m simply doing is I’m taking different sorts of code coefficients beta 1 and beta 2 and then I’m getting the linear combination of these two vectors we saw that in the simple case when we take a and we had to B so basically the coefficients are equal to 1 so 1 * a + 1 * B then the corresponding linear combination is equal to 1 and five it means that we are getting this Vector so one and five is in here which means that we are getting this one this Vector if we get if we take the zero as scal so beta 1 and beta two are both equal to zero then the linear combination of these two vectors is simply the vector zero which means that it is this point then if we take the linear combination using three and minus two as coefficients then we are getting this so 0o and three so one two and three this is three then this is our linear combination I can also take any other uh like scaled version of my B and of my a and then I will get entirely different sort of vector so let me actually show you a few more times um a couple of other examples so let’s say I keep my a so I just take the beta 1 equal to 1 but instead I scale my Vector B two times so this was at three I’m taking two times of my Beta which means that I’m here then I can take this I can add this to my a so this is 2 B this will give me another linear combination of these two different vectors I can also you might recall that we said that the starting point and the end point doesn’t really matter for for us what matters is that we uh have the same magnitude and the same direction for our vectors so this means that for me the vector being here and the vector being here doesn’t matter when I scale it two with two I can be here with three I can be here so this is the same as my B only three * B this is basically scaling B with three and this in here means that my Beta 2 is simply equal to three and then this means that I can combine this with my a which was in here you remember so this here this means that I get yet another linear combination of these vectors which means that I’m taking 3B and I’m adding on this my a so 1 * a my beta 1 is equal to 1 my Beta 2 is equal to 3 which means that the linear combination of this is equal to one 2 plus and then 3 * B is equal to 0 and then 3 * 3 is 9 this is then the new linear combination which is one and 11 so the new linear combination is equal to 1 and 11 so this thing which is the same as this thing and then you can go on and on you can also calculate the same with a negative B so you can take B and then you can scale it with minus one so this is minus b or you can go in here in here the same holds for a so you can scale it all the way to here or in the negative side so this already uh give us the idea that we will go into to the next point which is the span so when it comes to the linear combination and in this specific case when we have these two vectors we can combine these two vectors in any way and uh we can mix them up by using different sorts of coefficient of beta 1 and beta 2 and we will can we can get any Vector in our R2 so this means that any Vector in our R2 we can represent by using only these two vectors and this is not always the case for this specific case we are dealing with two vectors that we can use to represent any Vector in our R2 so what I mean here is that let me clean this up so independent what kind of vector you will give me in the R2 so it has two different elements it is 2 by one I can use a linear combination of A and B so a linear combination of A and B is beta 1 * a plus beta 2 * B in order to represent this Vector X1 and X2 therefore we are saying and we will come to this um in the next slide too that this pen of the vectors A and B so this is the set of all possible combinations of these two vectors is equal to R2 because any Vector in R2 can be represented as a linear combination of this two vectors so we have a linear combination of A and B and I’m saying that I can represent any Vector so here Vector X and this Vector X I’m representing by X1 and X2 and X1 and X2 can be any real numbers so X1 and X2 they belong to R and X is simply a two-dimensional Vector so X1 and X2 those can be any numers Z 0 1 2 – 100 anything and I’m saying any number in this two dimensional space so whether it is this one any Vector this one this one or this vector or this one any Vector that you give me in two dimensional space I can find a linear combination of this A and B that is equal to that Vector so I can represent that Vector as a linear combination of vector A and B that we saw before so let let’s actually prove that so I’m going to represent this uh X1 and X2 by a linear combination of this Vector A and B and how we can do that so we have beta 1 * a plus beta 2 * B it is equal to X1 and X2 where beta 1 and beta 2 so beta 1 and beta 2 they are constants so they are also real numbers so let’s unpack this which is beta 1 * 1 2 2 + beta 2 * 03 and this should be equal to X1 and X2 now this is equivalent of so beta 1 * 1 beta 1 * 2 plus beta 2 * 0 and then beta 2 * 3 and this should be equal to X1 X two so this is my beta 1 a this is my Beta 2 B and this is my X all right so now what we get is that and this is equivalent beta 1 * 1 is equal to beta 1 beta 1 * 2 is 2 beta 1 plus then here beta 2 * 0 is z and then beta 2 * 3 is 3 beta 2 so we have learned uh from the uh operations on the vectors that beta 1 uh so in this case when we are adding two vectors so beta 1 plus zero is the uh amount that we need to put as our first element so when we are adding two vectors we just need to take their corresponding elements we need to add them up so this equal to beta 1 + 0 and then 2 beta 1 + 3 beta 2 this is the result and this should be equal to X1 and X2 at least this is what I’m claiming so this zero doesn’t matter matter so we what we are getting from here is that beta 1 is equal to X1 and then 2 beta 1 + 3 b.2 is equal to X2 this is the two expressions that we are getting based on all these different calculations so let me actually remove all this so we have beta 1 is = to X1 and 2 beta 1 + 3 beta 2 is equal to X2 so here given that we have already that beta 1 is equal to X1 and here we have two unknowns I’m going to fill in the value for beta 1 in here so I’m going to take this and I’m going to fill in it in here here so for this volum so remember that beta 1 and beta 2 are two unknowns and X1 and X2 are just uh numbers that we will get when we uh know exactly the vector and we just want to represent that Vector as a linear combination of two vectors so when I take this uh value for beta 1 which is equal to X1 and I’m going to fill that in in here it means that I’m going to get from here that beta 1 is equal to X1 and 2 * X1 because beta 1 is equal to X1 and here I got beta 1 I’m just filling in the value for beta 1 which is equal to X1 so 2 * X1 and then the rest I’m just taking over three bet 2 is equal to X2 let me remember move this and from here what we are getting is that beta 1 is equal to X1 and I will solve this equation for the unknown which is equal beta 2 so I will just take the three beta 2 from left hand side I will leave it there and I will take this and I will take it over to the right so I’m taking X2 over and this two X1 so this part I’m just taking to the right two of the equation so minus 2 X1 which then on its turn is equal to so it goes to beta 1 is = to X1 and then beta 2 is = to X2 – 2 X1 / 2 3 perfect so what do we get here what is our end result and why is it significant so what we are getting here is that based on all this information without knowing beta 1 and beta 2 we got that beta 1 should be equal to X1 and beta 2 should be equal to X2 – 2 X1 / 2 3 this means that independent what kind of ex’s you will give me so what kind of vector we have in our AR 2 so this X1 and X2 they are just real numbers we can always find beta 1 and beta2 that we can use to represent that X1 X2 so our X Vector as a linear combination of these two vectors let me actually give you an example so let’s remove this so let’s assume we have a vector X and this x is equal to 4 and let’s say three so if we got this Vector X and we are saying we can use this Vector A and B to represent X as a linear combination of vector A and B which means that I can find I can find real number beta 1 and beta 2 that I can use to multiply the vector A and B respectively combine them together so they’re linear combination that will be equal to this Vector X so this is my X1 this is my X2 so this is equal to 4 and three Now using this let’s actually see whether that is true So based on this example my beta 1 should be equal to X1 which is 4 my Beta 2 should be equal to X2 which is 3 so beta 2 should be equal to X2 which is 3 – 2 * X1 which is 4 / to three and what’s this number this means that my beta 1 should be equal to 4 and my Beta 2 should be equal to 3 – 8 so 3 – 8 / to 3 and this is equal to- 5 / to 3 so this means that I can use a coefficients beta 1 is equal to 4 and beta 2 = to – 5 / to 3 to represent my Vector X as a linear combination of vector a and Vector B so let’s actually prove that too as a final step so let’s see where four times Vector a which is one 2 plus – 5 / to 3 whether this is indeed equal to Vector X so my Vector B is 03 so this is the first part and I want to prove that this is indeed equal to X and we already know what x is so this is equal to 4 * 1 4 * 2 plus and then here we got – 5 / 3 * 0 and then – 5 / to 3 * 3 this is equal to 4 * 1 is = to 4 4 * 3 is equal to 8 and then here we need to subtract minus 53 5 5 / to 3 * 0 is equal to 0 so this one is zero and then minus 5 / to 3 so 5/3 * 3 this ones are canceling out and we got 8 + – 5 so here the plus and here minus just to make sure we got everything right and this is equal to 4 and then 8 + – 5 is equal to three so you can see already that this amount that we got here is equal to X which was equal to 4 / to 3 and this helps us to uh verify and to know for sure that indeed while given any Vector in a two dimension space in our two x independent what this X1 is or X2 is we can always find a pair of beta 1 and beta 2 that will ensure that the beta 1 a plus beta 2 B is actually equal to this x where X A and B they are part of R2 and a is equal to one two and then B B is equal to 03 so we can represent any Vector in our two dimensional space as a linear combination of this Vector a with elements 1 2 and um Vector B with elements 03 and that’s exactly what we saw here because we could find any vector and we can represent this Vector as a linear combination of this Vector A and B this Vector as a linear combination of this A and B this Vector as a linear combination in any vector or a point in this plane we can represent as a linear combination of this Vector a and Vector B and in this specific case with this Vector a and Vector B we are seeing that Vector a and Vector B they spin R 2 so Vector A and B Spen R 2 now we will come to this definition of the span and just in general for different sorts of vectors we will see what this idea of span is but for now given that we just proved that we can represent any Vector in R2 as a linear combination of these two vectors A and B therefore we can say and we usually say it in linear algebra that the vector a and Vector B they spend R2 before moving on onto this concept of Spence that we just touched upon in our example I wanted to quickly go back to this example that I promised to discuss uh which was part of the definition of the linear combinations and unit vectors because we saw in our definition and let me just show you that uh the uh definition was providing these two highlights these two bullet points and was saying any Vector B in N Dimensions can be expressed as a linear combination of the standard unit vectors E1 to up to E n and the coefficients in this combination are the entries of B itself so let’s look into the example and see what we mean by that in this specific example we have this Vector B it is coming from the threedimensional space which we can see given that we have three different uh three entries so three uh elements in our Vector so it’s three by one and this means that b belongs to R Tre and in here we can see that B can be written as a linear combination of these three vectors so you can see that b is equal to min-1 * this Vector 1 0 0 so this one then we have + 3 * 0 1 0 Vector so this one and plus 5 * this third Vector which is 0 01 now we already know from the unit vectors that E1 is equal to 1 0 0 assuming that we are in three dimensional space E2 is equal to 0 1 0 and E3 is equal to 0 01 you can notice that that’s exactly what we got here this Vector is E1 this Vector is E2 and this Vector is E3 where E1 E2 and E3 belong to threedimensional space okay so another thing that we can see is that here we got coefficients minus one here three and here five so this is basically how beta 1 beta 2 and beta 3 using the common conventions that we saw before when describing the linear combination so let’s actually check that and then we will comment on these values so let’s check whether -1 * E1 + 3 * E2 + 5 * E3 is indeed equal to this B so this is equal to min-1 * this Vector gives us Min – 1 0 0 three times this E2 gives us 0 three and 0 and then 5 * E3 gives us 0 0 5 and this is equal to -1 + 0 + 0 is = to -1 0 + 3 + 0 is = to 3 and then 0 + 0 + 5 is equal to 5 now what do we get here we see that this which is equal to this it is equal to this Vector B indeed okay so now when we have indeed checked that B can be represented as a linear combination of these three vectors these unit vectors E1 E2 E3 another thing that we can notice and I’m sure you already did is that those coefficients they are not just randomly picked coefficients those are the entries of this Vector B so this is exactly what that definition was about it was saying that any Vector B including this example in in this case threedimensional space can be expressed as a linear combination of the standard unit vectors E1 E2 E3 Etc so this coefficients in this combination so you can see that the beta 1 beta 2 and beta 3 which are our coefficients in our linear combination they are the entries so this values of the B itself so the same will hold for four-dimensional Case five-dimensional Case n dimensional case so this means that if we write this down for General case just to ensure that we are clear on this part of the definition so if we got B Vector in N dimensional space so it got be one B2 up to BN as the elements of it comes from RN then we can represent this B as a linear combination of unit vectors coming from the N dimensional space so we got E1 E2 up to n that belong to n dimensional space and we can represent this B as a linear combination of these unit vectors so by using beta 1 times so this this is a common Convention of the coefficient as you might recall time C1 then beta 2 * E2 blah blah blah plus beta n * e n and what is important here is that this beta 1 beta 2 and beta n those are not just some coefficients but we already know what these coefficients are because we can then represent this beta by taking the values so those are the entries the elements of the vector B itself so it is B1 time B1 plus B2 times E2 dot dot dot Plus BN time e n where B1 B2 up to BN they are all real numbers so basically knowing what this Vector is this elements of this Vector we can always describe and express it as a linear combination of the standard unit vectors and if you’re wondering why is this important in some cases when performing different operations or working on different algorithms it just becomes handy to represent your vector as a linear combination of multiple vectors and in those cases exactly you can make use of this property of linear combinations to express your n dimensional Vector b as a linear combination of the standard unit vectors because everything is then down to you by having this Vector B you will already know what are the entri that you can use as your coefficients in this case beta 1 beta 2 so those are all these values coming from your vector itself and then the remaining is also known because you know exactly what these unit vectors are and how they are represented so here for instance the E1 is basically 1 0 0 blah blah blah blah 0 and then this is n by one vector here the E2 is equal to 0 1 Zer blah blah blah and then zero here so n * 1 again up to the point where you have the e n where you have all these zeros only the last element is one again n by one vector so this is the idea behind this second part of this definition which says that any Vector being n dimensional space can be expressed as a linear combination of the standard unit vectors E1 up to e n let’s now talk about other concept which is also super important which is the span of vectors so by definition the spend of a set of vectors is a set of all possible linear combinations of these vectors so if V is equal to V1 V2 up to VK and is a set of vectors then the span of V is written as a span V and it includes any vectors that can be expressed as C1 V1 up to C2 V2 up to CK VK so basically it is a common uh notation uh to say that if we got for instance vectors V1 V2 up to VN so we have n different vectors then we say that the span of V1 V2 up to VN that this is simply the notation that we use in order to describe this Spen of this vectors and we briefly spoke about this concept of span when we were looking into our example that we saw before so you might recall this vectors A and B that we had and we saw and we said that the span of a and b is the entire space in the two dimensional uh real number space so we said that span of a and b is equal to R2 where our Vector a was simply equal to 1 2 and B was equal to 03 so we proved that the span of one two and 03 was the entire R2 and how we knew that because we proved that any Vector in R2 could be represented as a linear combination of these uh two vectors so so you might recall that we solved this equations we saw that independ what kind of X1 and X2 uh one will give us we can always use the um U we we found this amounts let me see where I can find it back I no longer have this so we saw that for uh specific values of um beta 1 and beta 2 we can always get a linear combination of this A and B in order to get our desired vector X so beta 1 * a plus beta 2 * e will always then be equal to X1 and X2 if our Vector a and a vector B are those but of course this doesn’t hold for all the vectors so not for all uh two-dimensional A and B uh we can say that the spend of these vectors is the entire R2 therefore to better understand this concept of span and this concept of span of vectors I wanted to distinguish five different cases one of which we already spoke about and that is the case when we had this Vector a and Vector B and we said that the span of a and b is the entire R2 but we will also look into the case when we for instance have a span of the zero Vector the span of a single vector and the span of perpendicular vectors we might also look if there is time left we will also look into the span of parallel vectors so let’s now look into this cases one by one so let’s say we have a vector of zero so we have zero Vector so this is a very simple case we will start with the simplest case and we will move on WE two more advanced cases if we have a vector a that is a zero Vector 0 0 then independent what kind of scal we will use to scale this so let’s say um we Define it by C so C * Z independent what kind of scalar we will use this will always end up being equal to 0 0 so if C is equal to z c * 0 will be equal to 0 if C is equal to 1 C * 0 will be equal to zero or C is equal to 100 C * 0 will still be 0 0 so independent what kind of scal we will be using what kind of linear combination we will create from our Vector a this will always stay in here so the point the vector will always stay in here in our two Dimension space so this is completely different from what we saw before when we could create and we could take any Vector in our R2 and we could represent it as a linear combination of these two vectors that we saw in the previous example so in this specific case um scaling the zero with independent of any scalers we use this will not change the magnitude nor it will change the direction of our Vector so no matter how we scale it we still get zero this means that the span or zero Vector is just the zero Vector itself so you can see that independent what I scale the zero Vector I always end up with the same zero Vector so therefore the span of the zero Vector is equal to zero because by definition the span of set of vectors is the collection of all possible vectors that I can reach by performing linear combination and in this case I will always Reach This Z 0 Vector so all possible collections of these vectors are the vector 0 0 which is single vector and the same as the input so this is the basic case now let’s move on onto a bit more uh Advanced case so bit more complicated than this one but itself also very easy which is when we got a single Vector a so let’s say a a is equal to 1 and 2 now I want to know what is the span of a in order to know what is the span of a we simply need to understand what are all these possible collections of vectors that I can get when I’m uh combining um a I’m multiplying a with different coefficients so what are the all possible linear combinations of this Vector because I got just single Vector a so a is one two which means one in here and then two here my a is this vector and let’s look into uh different uh scalar multiplications of this Vector so let’s say I want to calculate C * a so the scalar multiplication of this where C is equal to C is = to 2 C is equal to 3 C is = to uh min-1 C is = to Min – 3 and of course C is = to 1 so in all these cases when C is equal to 1 then the linear combination in this case just the scaled multiplication of this single Vector a so 1 * a is simply equal to one and two so the same Vector a c is equal to 2 this will give me 2 and four C is equ 3 this will give me 3 and 6 C is = to min-1 will give me -1 – 2 for my a and then C is = to -3 will give me -3 and then Min – 6 so let’s plot each of those so if we got for instance C is equal to one case you can see that we already got that Vector in here so it is this Vector when C is equal to 2 then we got this one so two and four so where is that it is in here let me use another color it is in here when we got say is equal to three then we got so this one three and six so this is three and this is six so it gives me this vector in the next example so in the next linear combination we have C isal to minus one so we got min-1 and min-2 so where is min-1 it is in here where is min-2 it is in here so I’m getting this vector and then finally when I have let me change the color when I have C is equal to minus 3 so this case then I got minus 3 six which means that here is my minus 3 here is my- 6 so we got this thing so you already should see what is going on here when we got just a single Vector for which we need to know what is a linear combination and that Vector is not a zero Vector it has nonzero elements but um it’s still it is just a single Vector then all its linear combinations given that it is simply uh scaled multiplication of it we are all getting them on the same line so you can see all the linear combinations of this single Vector is just a scaled version of it and it lies on the same line so what this tells us is that essentially you can move along the line defined by this Vector a but you cannot leave it so you cannot get a vector that is in here that is in here that is in here in here here so you cannot leave this uh line you will always stay on this line so this line essentially span of a so when we got a single vector and that Vector is not equal to zero Vector then the span of a is equal to and this can be expressed as C * a given that the C is a real number so we already saw this in depending on what kind of scalar we will take any linear combination of it will end up simply this C * a so therefore we are generalizing this and we are seeing that the span of a so to set of all possible linear combinations of this a is simply equal to C * a given that the C is a real number this is basically the spend of a real uh uh Vector in a two dimensional space let’s now look into the next case the next example when we will calculate or we will Define the span of a perpendicular vectors so let’s now look into another example when we are looking for a case when the um when we want to find out the span of perpendicular vectors so imagine we have these two vectors Vector a and Vector B where a is equal to 1 Z and then B is equal to 01 so we are still in our lovely uh two dimensional space so let’s first visualize the vector a it’s quite basic it is this one and then Vector B it is simply this one so we can already see why they are perpendicular so you can see that they are forming this um 90° angle so right angle here and then we know that the spin so that’s exactly what we want to find out so the span of a and b and this is what we want to find out out and we know that the span of two vectors is the set of all possible linear combinations of these vectors so we want to see what are these all possible linear combinations of C1 so all the possible outcomes that we will get when we get a linear combinations of these two vectors so basically C1 times a plus C2 * B Because those are all the linear combinations of these two vectors C1 * a + C2 * B nothing thing that we can see here quickly is that C1 * a so this part those are all the skill sced versions of a so scaling multiplications of a and this second term in the linear combination those are all the scaled variations so scalar multiplications of vector B which means that and we already have seen this time and time uh again that when it comes to Vector a all its linear combinations they will lie on the same line so let me take this color so if I do 2 a so C1 is equal to 2 then I will be in here if C1 is equal to three then I will be here C1 is equal to 4 I will be here C1 is equal to 10 I will be in here and then the opposite holds as well if C1 is equal to for instance minus uh 2 then I will be in here if it’s equal to Minus 5 I will be uh my Vector will look like this and so on so this means that all the scaled multiplications of vector a will lie on this line so I can also say that the span of C uh the span of a so span of a is simply equal to C1 a so you can see in here so on this line basically so this is C1 a so this basically means independent what kind of C1 I will take with is 1 2 3 0 – 5 – 100 I will always end up on this line so this line so this is about the uh scaled multiplication of a but of course to create this linear combination of A and B we also have the second element which is the all possible scaled multiplications with a vector B so C2 B2 so let’s see what that looks like so if I for instance take C2 is equal to Z I will be in here if I take C2 is equal to uh two I will be in here C2 is equal to 5 I will be in here C2 is equal to Minus 5 I will be here so you are already seeing what is happening here so all the power possible scaled multiplications with Vector B will be on this line so now we are then getting that the span of B will then be equal 2 C2 and then B and here I’m not using formal notation I’m just trying to um I’m just trying to to uh draft the idea of the span of vector a and uh span of vector B because we are not uh done yet we still need to combine the two in order to find the span of vectors A and B when they are perpendicular so when this angle is simply 90° okay so let’s also add this on our plot so this is C2 and then B so this already gives us an idea that all the possible combinations of the two so when we add these two elements to each other the outcome will always lie on this two lines but there is no way that we can find any other coefficient for C1 or C2 that can help us to get a value that will be so a vector that will be in here or in here or in here or in here that’s just not possible so just you can try to go ahead and solve that equations like we did before and you will see that there there is no way that you can pick here a line and you can represent it as a linear combination of these two vectors it just not possible and later on we will see why but just keep in mind for now that once we have this this type of vectors when two vectors are perpendicular then um we cannot find a line a vector that is outside of these two lines so here you can see the x-axis and the Y AIS but it can also be like this it can also be like this but then you cannot find any other line that lies outside of this area that you can uh create a linear combination of these two different vectors and then you say then you cannot say that you can create a linear combination of these two vectors A and B so therefore when it comes to defining the pan of this two perpendicular line we say that the span of a and b given that A and B are perpendicular but also given that this values in this case you know a is equal to 1 is z b is equal to 0 and 1 then their span you might have already guessed is equal to C1 a plus C2 B given that C1 and C2 are of course real numbers so in this case C1 and and C2 as expected are just scalers so they are just some real numbers coming from R and uh this a A and B those are vectors that are being spent and in this case specifically the vector a is equal to this one Z and Vector B is equal to 01 and this expression that we see here this pen this simply describes the set of all possible vectors that can be formed by adding the scaled versions of this A and B so C1 a plus C2 B in order to form this linear combination so this set this set of C1 a plus c2b which is a linear combination all possible linear combinations of these two vectors so um it effectively covers the entire plane illustrating that any point in 2B space can be reached by some combination of A and B let’s now move towards our final example that we saw also as part of our definition for the span of vectors in order to check and to learn how we can usually check uh whether the two vectors they really spend the entire space so in this case we got two vectors we got Vector uh V1 which is equal to one two and Vector V2 which is equal to 34 so in here and also um we uh have in our example that it says the span of V1 and V2 is all over the R2 because any Vector in R2 can be expressed as a linear combination of V1 and V2 so the example basically is saying that if we know that um we can express any Vector in R2 as a linear combination of V1 and V2 then we say that the span of V1 and V2 is the entire R2 so let’s actually go ahead and prove that from our example so we have X which we can represent as X1 and X2 and X1 and X2 are just real numbers and we got V1 which is 1 2 V2 which is 3 4 and we got in our example that uh we need to prove that the span of V1 and V2 is the entire R2 so for that what we need to do is we need to prove that we can express our coefficient C1 and C2 in such way using X1 and X2 that independent of what is X1 and X2 are so what kind of X Vector we have whether this is like one two or this is 04 or this is th000 and uh 5,000 independent what kind of vector we get uh we give here so X1 and X2 values as long as those are real uh numbers we can always find a set of C1 and C2 that we can use as coefficients in order to create a linear comp combination from vectors V1 and vs2 and in that case we say then the span of V1 and V2 is the in R2 okay so let’s go ahead and actually prove that using our previous knowledge that we already gained so keeping in mind that C1 and C2 are unknown numbers for us whereas X1 and X2 are just a way to describe those elements in our Vector X that will be provided to us so X1 and X2 will be basically known and C1 and C2 are the unknowns that we are chasing so for that the first thing that I’m going to do is to describe this linear combination that we got here C1 V1 plus C2 V2 with actual equations unknown equations and the way I’m going to do it is by simply filling in this Vector V1 and Vector V2 um vales so we have C1 and then C2 here and then here I got one two plus and then three and 4 here and what is this amount so this is equal to let me actually go on to the next row so we can create um set of equations for this so This equal to X and we get C1 * 1+ C2 * 3 is equal 2 2 and remember that this is X and we said that the x is equal to X1 and X2 so this basically equal to we can right here is equal to X1 and X2 so this is then equal to let’s not skip all the steps X1 and X2 so here then the second elements need to be added so C1 * 2 and C2 times 4 which is then the same as C1 + 3 C2 and then 2 C1 + 4 C2 and then this we are saying this Vector is equal to X1 and X2 so this is what we have here and let’s move from the vectors to equations so given that we have this we are allowed to say that this gives us actually two equations this means that this element this element from this part should be equal to this and this element should be equal to this now let’s write it done we see that C1 plus 3 C2 should be equal to X1 2 C1 + 4 C2 is equal to X2 this is all that we see in here let’s remove this to keep the space clean now what this means is that we have two equations with two unknowns C1 and C2 and X1 and X2 are the numbers that will be provided to us as part of our Vector so what we want to prove is that we can describe and we can express C1 and C2 which are our unknowns using a X1 and X2 so you see here this is C1 C2 those are our nouns and we want to describe them by using X1 and X2 and very soon we will also see why so for now let’s try to express those two unknowns using our nouns like X1 and X2 so here I already see that C1 is alone so there is no scaler so I will make use of that opportunity to keep the C1 one on the left hand side and I will take this this amount to the right so I will say C1 is equal to X1 minus 3 C2 okay slightly better so I have C1 at the left I do have X1 in the right but I also have 3 C2 in here but another thing that you will notice is that in my second expression here I got 2 C1 + 4 C2 + 62 I want to have the C2 on only because then I will have an expression of my C2 only using X1 and X2 um so numbers that are that will be provided to me that are n so for that what I’m going to do is basically trying to solve uh two equations with two unknowns exactly the same um process so I’m going to take this C1 from the first equation and I’m going to fill in in the second equation so I going to say two * and here I’m going to fill in that C1 expression from here so X1 – 3 C2 so this is my C1 plus just taking over this part so 4 C2 is equal to X2 okay perfect so now what I end up with is C1 is equal to X1 – 3 C2 just taking it over and then here I’m opening parenthesis which is 2 X1 – 6 C2 plus 4 C2 is equal to here I forgot an X2 is equal to X2 okay one step closer why because I in my second equation I no longer have a C1 I only have a C2 which is great which means that this gives me an indication that I can reun the C2 which is unknown with nouns with X1 and X2 so let’s make use of that opportunity the first equation I would just take over so C1 is equal to and then X1 minus 3 C2 and then here I will do 2 X1 and then here we got two * c2s which means we can combine them so minus C uh minus 6 * C2 + 4 C2 it gives me – 2 * C2 and this is equal to X2 all right let’s now solve that so what I want to have is just the C2 in the left hand side which means I need to bring all this to the right and I need to get rid of them such that I can leave the C2 in the left entirely alone so this is what I’m basing basically chasing for that I’m going to once again rewrite C1 is equal to X1 minus 3 C2 and this time I’m going to take them minus 2 C2 here I’m going to leave that in the left but then this one I’m going to bring to the right so X2 – 2 X1 here I need to be very careful to not make a mistake CU that will mess up my entire calculation all right so now we are one step closer just taking over the first equation again so C1 is equal to X1 – 3 C2 and here what I need to do to get rid of this minus 2 is to divide the two sides so both 2 minus 2 cuz that will help me to keep the C2 only in the left alone without any scaler so the C2 is than equal to X2 – 2 X1 / 2 – 2 so this is what I end up with perfect so we are very close stay with me so um here what we are getting is that C2 is equal to this amount we see that now we no longer have any other C’s in here which is great and remember that X1 and X2 will be numbers that it will be provided to us I just wanted to keep everything General and then uh another thing that I want to fix is this C2 because the C2 is an unknown and I want to fill in uh this value of C2 in here such that for the C1 I will have a similar picture so in the left hand side I will have C1 in the right hand side I will Express the C1 with no number so X1 and X2 but not the C2 or others all right so let’s then go ahead and do that first I will write C2 in a simpler way so C2 is equal to here I got a minus I will just write here minus so I will take the minus over here and then I will write X2 – 2×1 2 um be super careful with this minus therefore I’m using parenthesis so now I’m going to use this C2 and I’m going to fill that in in here so C1 is equal to X1 minus 3 times I can also make it plus because minus of here so minus of here and minus of here will cancel out therefore I will do plus three times and then X2 – 3 X1 / 22 and this then gives me C1 is equal to X1 + 3 / to 2 * X2 – 3 sorry 2 almost made a mistake 2 X1 and then C2 is equal to X2 – 2 X1 / 2 2 and here we got minus Perfect all right awesome so now we have expressed X1 and X2 well careful with this X1 and X2 with only noun numbers now what I’m going to do is that I’m going to prove that independent what kind of X we will be taking here we will end up getting the C1 and C2 using this what we just found here that will give us a linear combination of these two vectors that will be equal to that X so for that so to prove that this patter of V1 and V2 is the entire R2 I need to prove that in depend what kind of X I will take so X1 and X2 I can always find the C1 and C2 that I um just calculate in here using that X1 and X2 that I can then use to combine with my V1 and V2 to find the linear combination of these two vectors with that C1 and C2 which will be equal to this X so for that what I need to do first is to take such a uh random X so let’s say my X is equal to 0 and 4 this means that my X1 is equal to 0 and X2 is equal to 4 what this means is that this gives me C1 which is equal to and here X1 so I’m basically filling these two values for here to obtain my C1 so C1 corresponding to this specific Vector X so X1 is equal to 0 which means I end up C1 is = to 0 + 3 / to 2 * X2 is equal to 4 so 4 minus and then 2 * X1 is = to – 2 * 0 which is 0 and then C2 is = 2 minus and then X2 is equal to 4 so 4 and then minus 2 * XY is = to 0 0 and then this divided to 2 now what are those numbers so C1 is equal to 3 / to 2 * 4 which is 3 * 2 so 6 and then C2 is equal to minus 4 and then minus so this is zero this cancels out which means 4 / 2 is 2 and then C2 is equal to – 2 so basically I have calcul calculated the coefficients C1 and C2 by just knowing what is this Vector so knowing X the provided X1 and X2 I have calculated my C1 and C2 using my derivations in here so let’s now get rid of this this calculations to clear some space and to do the final part which is compute the linear combination of vector V1 and vs2 for this specific coefficients well knowing what this given Vector now is this example random Vector so the C1 is equal to 6 which means six times and then Vector V1 is one 2 so this is first part of my linear combination plus and then C2 is equal to minus 2 * then here three 4 what is this this is equal to 6 and then 6 * 2 is 12 plus now let’s calculate the second part – 2 * 3 is – 6 and – 2 * 4 is – 8 so what does this give us 6 – 6 and 12 – 8 this gives us0 and four nice so this confirms that we have done everything also correctly which is great because we have seen that using this C1 and C2 that we have just calculated we have successfully comp uh computed the six V1 so linear combination of this uh two vectors V1 plus minus 2 minus 2 and then V2 and we have seen that this linear combination is equal to 04 which is exactly our X so in this way we have proven that independent what kind of vector we will pick what kind of X we will pick here we can always find and calculate the corresponding coefficients C1 and C2 in the same way as I just did and then by using those when we calculate the linear combination of these two vectors with this specific coefficient this will be exactly equal to X and this proves that inde depending what kind of vector we have in our R2 we can always express that as a linear combination of the vector V1 and V2 and this proves and this concludes our proof that span of V1 and B2 is the entire R2 all right so we are very close to finishing up this unit so the next topic we are going to talk about is a linear Independence and all this important stuff that we learned as part of the previous modules are going to become super handy as part of this specific concept so we just spoke about the idea of span we have plotted a lot of vectors we have seen the linear combination of that and how we can find out whether the span of multiple vectors is the enti space uh for instance the R2 or it is just the line or it’s maybe the zero Vector we have seen many examples and many operations we have also seen this idea of unit vectors and we are finally ready to come to this very important concept which is a concept of linear Independence so by definition linear Independence says that the set of vectors is linearly independent if no Vector in a set can be written as a linear combination of the others otherwise they are linearly dependent so vectors V1 V2 up to VN are linearly independent if and only if the only solution to the equation C1 V1 plus C2 V2 plus CN VN isal to Z is C1 is equal to C2 up to CN is equal to Z in other words in a lar linearly independent set the equation C1 V1 plus C2 V2 plus CN VN is equal to zero has only the trival solution where all CIS are zeros so now what do we mean here there is a ton of information in this definition so let’s unpack them firstly it’s TR important to uh keep in mind this idea of Independence and dependence Independence and dependence there are things that we commonly use in data science in artificial intelligence in statistics so those are really important so we basically have linear independent condition so there is a certain condition that our vectors should satisfy vectors in our set in our Vector space for them to be named as linearly independent and otherwise we are calling them linearly dependent and you can you can see that here there are a couple of Parts as part of this definition first it talks about um being unable to recreate a vector in a vector set while using the remaining vectors in our set so it says if you can use the remaining vectors in your vector space and linear create a linear combination of them so linearly combine them and we have already seen the definition of linear combination so if we cannot create such linear combination from the remaining vectors to get our Target Vector then we are saying that we have a linearly independent vectors so if we want to say that all our vectors in our Vector set they are linearly independent it means that each of those vectors we should not be able to recreate out of the remaining vectors so we should not be able to find coefficients to create linear combination using the remaining vectors in order to get our Target Vector now what do I mean by this target Vector what do I mean by this linear combination uh I will come to this in a bit for now let’s just try to unpack this definition cuz uh with examples uh we will definitely go through this step by step in detail such that this idea of linear Independence and dependence is super clear so in this second part of the definition it says vectors V1 V2 up to VN are linearly independent even only if the only solution to the equation and we have here in the left hand side you might recognize the linear combination of our vectors V1 up to VN so in in the right hand side you have zero so you are saying our linear combination of vectors is equal to zero if and only if C1 C2 up to CN is equal to zero so linear Independence basically claims that we will have linearly independent vectors only if and only in the condition when um the only way we can create linear combination of these vectors equal to zero only if those coefficients are zero there is no other way that we can get a linear combination that is equal to zero while those coefficients are not zero so the only way that we can get a linear combination out of all our vectors equal zero is only when all of the coefficient C1 C2 up to CN is equal to zero that’s something that we will come later to this again there something also that we are going to come back in our next module and the next one so um this one will be also super clear once we go through those modules but for now keep in mind that the uh linear combination of all these vectors can only be zero in case when all these coefficients are equal to zero so and then we have the third part in our definition which says that in other words in a linearly independent set the equation C1 V1 + C2 V2 up to CN VN is equal to zero has only the trivial solution where all CIS are zero so this explanation is basically what we just talk about as part of this second part where we said that only in case the coefficients are all Zer we can have a Lear combination of our vectors V1 V2 up to VN which is equal to Zer and why we would like this linear combination to be equal to zero because it’s a common way to find solution to our linear system so this is something that we will also see as part of the next module when we will be discussing the IDE of solving l your systems we will go into more uh Advanced topics but for now in order to understand this idea of linear Independence we should just keep in mind that we cannot find any CIS so C1 C2 so any coefficients that is not equal to zero and then expect that the linear combination of these uh linearly independent vectors is equal to zero so that’s the uh if and only uh if and only uh if part which means that this holds from both sides on one hand we have V1 V2 up to VN which are linearly independent only if the linear equation so the linear combination of all these vectors is equal to zero if all these coefficients are zero but also the other way around holds as well so if we have a linear combination that is equal to zero only if those coefficients are zero that means that we are dealing with a linearly independent vectors this is the if and only if part which means that we have this uh conditions from both sides if one holds the other one holds but also the other way around all right so let’s now look into specific examples that will make our journey in understanding linear dependence much more convenient so let’s say we have our coordinate system and we have these two different vectors so we have Vector let’s say 2 and three which is our Vector a and we have a vector B that is equal to 6 and nine so those two are our vectors and what we want to understand is whether those two vectors are linearly independent or linearly dependent so one thing that you can quickly notice is that b looks quite similar to a in terms of its scales so there is a way that we can recreate Vector B by using Vector a now you can see that if I take Vector a which is equal to 23 if I take Vector a and I multiply it by three so three * Vector a this is a scale multiplication then what I can get is three times and then I have here 2 3 and this is then equal to 3 * 2 is 6 3 * 3 is 9 this gives me 6 and N which is our uh Vector now another thing that you can notice that that is exactly my B so you can see that those two are similar which means that 3 * a is equal to B now what this means is that I can recreate Vector B by using Vector a so in our definition we saw that a set of vectors is linearly independent if no Vector in the set can be written as a linear combination of the others so here I can take this 3A as a way to write down a linear combination so 3 a + 0 * B is then equal to B which is basically saying 3 a is equal to B so so by using these two vectors in a set I can then create a linear combination of the two and actually even basic way of writing this is saying I can use the vector a to write a linear combination from this so 3A is a linear combination so just a scaled multiplication in this case of course but if we have just two vectors our Target Vector is B and I want to write this uh I want to see whether I can rewrite the vector b as a linear combination of the remaining vectors which is Vector a so I can then write Vector b as a linear combination of vector a because I can say that 3 * a is equal to Vector B so this means that Vector a and Vector B they are linearly dependent this means that I can use Vector a to recreate Vector B and of course I can also do the other way around right what I can do is that I can just take Vector B so I can take Vector B I can multiply it by 1 / to three 1 / 3 is real number so I’m just performing a linear combination using B and this will give me 6 / to 3 is 2 9 / to 3 is 3 and I’m getting exactly what I have under a so I can then also rewrite Vector a by using Vector B so I created a linear combination using Vector B in order to get a vector a and that’s exactly the opposite what we have learned here because we should not be able to write this vectors using the other ones in our set because otherwise we have a linearly dependent set therefore we are saying that Vector a and Vector B they are not a set that is linearly independent but they are linearly dependent before moving on to another example I also wanted to visualize the vectors just to see what is going on with this pen and uh how are the two linearly dependent vectors look like in R2 so this is our R2 we have a vector a which has two three elements so we know already the magnitude and the direction this is two this is three which means here let me actually use another color so 2 three which means this is my Vector a and then my Vector B is simply 6 and N so it is this one so you can already see what is going on so this is Vector a and this entire thing is Vector B and you can see that those two vectors no matter how I combine them I can I will always get the combination so linear combination of the two on this line if I want to get um Vector that is for instance in here I can never find a scalers of C1 and C2 in such way that these vectors so A and B they can form a linear combination that will give me this Vector there is no way that I can do that and that’s why uh we say that the span of these two vectors so span of a and b with this A and B is this line and we cannot express any of these other vectors like this one or this one using a linear combination of these vectors A and B the only linear combinations that we can recreate using these vectors A and B are on this line so you can see that even if I have two different vectors I actually just got um single Vector because I have two three and both of these vectors they are actually um uh scaled multiplication of the other one so B is equal to I’m missing here something 1id 3 so B is simply equal to 3 * a and then a is equal to 1/ to 3 * B so in both cases there are simply a version of scaled multiplication of this Vector 2 Tre so a is simply equal to B time 13 and then B is equal to 3 * a and both of them they are actually based on this Vector two a tree on this Vector a so therefore they both actually form and they span around this single line and they are both linear we also call it collinear and they are linearly dependent okay so let’s now move on to the next uh example where we will have bit more interest in case and we will look into this example when we have linear Independence look into another example bit more interesting one as we want to see whether those two are linearly independent or not so the first Vector that we got is the vector a the vector a is equal to 6 and Z so it is this vector this is Vector a the vector B it is this one and it contains element of zero and seven so it is this Vector this is the vector B now in our definition of linearly independent vectors we saw that the idea of linear Independence is that the two vectors can only only be linear independent if we cannot rewrite one of them by using the other so this means that we cannot rewrite a in terms of B and we cannot rewrite B in terms of a so there is no way that we can scale the vector a to get Vector B and there is no way that we can scale Vector B with vect with some uh scaler in order to get D Vector a so there is no way that we can create a linear combination of this one V VOR to get the other one and the other way around so let’s see whether this is the case just from uh trial and error we have a vector a which contains elements 6 and zero for us to go from A to B that has elements from so we need to go from 6 to zero in this case and we need to go from 0 to 7 now we can automatically already from the second element that there is no way that we can go from 0 to 7 you cannot find any scaler C that you can multiply with zero in order to get seven there is no way that you can do that because any number any real number that is a real number if you multiply it with zero it will never become seven and of course another thing that you can notice here also very quickly is the other way around right so here if you go from this zero to six there is no way you can go from this 0 to six because there is no such C that you can take this zero and multiplying it with that so here our scaler and you get this equal to six this is just not possible so what we are seeing here is that there is no way that we can somehow change these vectors so there is no way that we can scale them in such way so this is minus B so all the scales scaled version of this so all the um scaled multiplications of vector B they will always be on this line and then the same holds for a as well so all the scaled multiplications of a will be on this line so then one thing we can quickly see here is that given that those two are perpendicular this pen of A and B is the entire R2 so we can see that by using those two lines we can recreate any other line in this R2 and this is highly related to this idea of linear Independence and given that we cannot come up with a linear combination using the other vectors to recreate the other one in this case given that we cannot recreate a using B and we cannot recreate B using a so no linear combination that exist that we can use to rec create Bay using a and the other way around we are saying that Vector a and Vector B are linearly independent let’s now look into another example that will uh clarify this linear Independence concept so we have three different vectors and the first Vector is Vector vect a 1 0 0 Vector B uh 0 1 0 our second vector and the third Vector 0 0 1 you can notice that we are in R Tre and then the example goes on and it says that those three vectors are linearly independent and as an explanation we have that there is no way to add these vectors together with any scalar multiples to equal the zero Vector unless all scalers are zero now before even going on to next part it’s actually very quickly um uh provable that those three vectors are linearly independent and you cannot create a linear combination of one using the remaining of the two let’s look into this example in more detail so we have three vectors A1 A2 sorry B so we got a B and C which are 1 0 0 0 1 0 and 0 01 now you can quickly see that if we are in R3 and this is actually our unit Vector E1 this is our unit Vector E2 and this is our unit Vector E3 because in that positions we got our ones and the remaining there are all zero and this is actually very similar to the previous example because we can quickly see how we are we will not be able to recreate one vector using the OD on by even looking at the positions of the zeros so for us to recreate Vector a which is equal to 1 0 0 it means that we should be able to find a linear combination C1 C2 and then using these vectors this is the vector B 0 1 0 plus C2 * Vector C which is 0 0 1 so so in here basically we are already seeing a problem because we have here an element one and we somehow need to be able to find C1 and C2 in such a way that 1 is equal to C1 * 0 + C2 times 0 but we know that there is no C1 and C2 that we can find so this uh expression actually is true because C1 and C2 they should be real numbers and there are no real numbers that we can find to multiply with zero such that this will end up to one because this is always equal to zero and we basically get one is equal to zero which is not true and of course the same holds the other way around you can prove that B can never be um recreated by using the linear combination of a and c and also the C can never be recreated by using a linear combination of A and B therefore we are saying given that a can’t be written as linear combination of B and C B can be written so the same only this time A and C and then C hun be written as linear combination of A and B those vectors A B and C they are linearly independent and even stronger you can actually go ahead and prove that this pen of these three vectors is the r Tre but that’s outside of the scope of this example so we will just pass but I will leave that um to you to prove all right so now when we are done with that let’s actually move on to the last module which is the dot product and its applications so uh the length of a vector and Dot product is a concept that um we um are familiar from the high school so the length of a vector is deeply related to this dot product idea the dot product of a vector v WID itself gives this a square of the length of V what basically um it means is that this dot product of vector v so this thing which means take the vector v and multiplying it with the with the other vector v is simply equal to the square of a length of B so this is way to express the length of the uh of the vector v and once we square that that is the dot product so that’s basically this definition what is about about so we know what this definition of the distance is and we Define it by this and then we take the square of that distance and that is our DOT product and we are going to see this idea of dot product a lot especially when it comes to uh matrix multiplication Vector multiplications also in many applications of linear algebra you will see this idea of thatt product coming again uh and coming back to us so uh this is a concept that we really need to understand so in the two Dimension space let’s say we have a vector B which is um consisting of the two elements X and Y then the dot product and the link are related by V by V this is the way we denote the dot product so we just simply use the dot and the name also makes sense because we are saying we are using the dot to perform dot product so we are multiplying to we are creating the product of this Vector with itself and this is equal to x² + Y 2 which is equal to the um square of the distance of this Vector now you might recall from the high schol that we have learned this idea of distance so if we have xaxis y axis then we basically use this uh x² + y sare to uh get the uh you know the formula for from our Circle and then uh we have the x² + y Square we take the square root of it and then this is our distance so once we take the square root of that square of that from this uh square root of x square + y Square then we are simply getting this two cancel out which is equal to x² + y^2 So This is highly related to this idea because we are again talking about distances and we are simply taking the distance since we are squaring them up and then we are getting the dot product so this the double uh straight lines this is just a notation that we use and we spoke about this also before this comes um from the prealgebra and this um this is highly important related to this idea of PAG theorem and how we compute the distances so for instance when we have this uh Square triangular so we have this um uh rectangle here and we have here the 90 uh uh gr so here we have the rate uh right um angle and here we have our C which is uh the side right in front of this uh 90° angle and here we have the A and the B and we say that c² is equal to a sare + b sare and if I were to actually write this in terms of X and Y so if this side is X and this side is y and this is my Z let’s say then z s would be equal to x² + y² and this is something that we can see here too and the two terms are highly related so the Z squ is equal to x² + y s and this is simply equal to Z * Z right and this is something that we know from High School welcome to the module one of this new unit when we are going to talk about about mates as as linear systems so those are all fundamental concepts that you will see time and time again when applying linear algebra not only in mathematics but also in applied sciences like data science artificial intelligence when training different machine learning models and trying to see what is this mathematics behind machine learning models different optimization techniques when you want to solve different problems using linear algebra so in this first module as part of found found ations of linear systems and matrices we are going to introduce this concept of linear systems and then we are going to talk about the general linear systems we are going to uh see this common labeling all the coefficients this idea of indices that refer to the rows and the columns we’re going to see what is this differentiation between homogeneous and nonhomogeneous systems so without further Ado let’s get started so uh the linear systems form the um bedr of linear algebra modeling this area of problems thanks to this advancements in this linear systems and solving it in Computing we can now solve a large amount of problems in a very efficient and a fast way so uh the general linear systems can be represented by this uh set of M equations with n unknowns in the previous unit when we were looking in to this uh linear combination of vectors we saw this notation which was A1 and then we had C1 multiplied or rather let me keep me uh let me keep the same notation so we had this linear combination of vectors so we had beta 1 and then we had A1 Plus beta 2 and then A2 and those are all vectors Plus A3 so beta 3 * A3 dot dot dot and then beta M time a m this is the notation that we saw before and we said we want to come up we wanted to come up with the linear combination of these different vectors A1 A2 A3 up to a m and then we use that in order to get a sense of whether we are dealing with linearly independent variables vectors or larly dependent vectors and then we also commented on the span that these vectors take now when it comes to um the uh vectors and just in general linear systems we can represent what we had before now in terms of with a bigger system so in terms of M equations and with n unknowns so here what you can see here is that we have M different equations so we have beta one B1 B2 up to BM so you can see it in here and then each of these equations it contains n unknowns so you can see that the unknowns it stays the same so the unknowns are those X1 X2 up to xn so X1 X2 up to xn are the set of all n unknowns and then M equations that you can see in here are all this equations so a11 x1+ a12 X2 dot dot dot and then a1n and then xn is equal to B1 and here one thing that is really important to keep in mind is that the indexing is what we need to focus on so we need to keep this one in mind this a i j and this XI so this is something that we also spoke about when uh discussing the linear combination of vectors we slightly uh touched upon on this topic so let’s now dive into this this indexing and how do we index is a i j what are this A’s what are this J’s and here you can see that we have a11 and then a12 and then up to the A1 n and this is in our equation one and then we have in our equation two A1 2 let may actually write this with a different color so in our equation two we got a 21 a 23 up to a 2N and this a that you see here those are just real numbers so so a11 can be 1 a12 can be three A1 n can be 100 and then the same also holds for this B1 for this B2 and for this BM and all these values A’s and B’s they are just real numbers the only unknowns that we got here are those so the X1 X2 up to xn all right so what about the indexing now so we got a i j and as you can see in this case the first thing that we can see here it stays everywhere the same which is the one so we got here one we got here one and up to the point we got here one whereas the second Index this one it does change it grows grad with one and it becomes it goes from 1 to two and up to n so you can see here that the first index first index or index I it goes from one it doesn’t change it’s just one so it is 1 one and one so here in all cases for this equation I is equal to 1 but another thing that you can notice here is that the index two unlike index I so the second index which is the J so you see here that the second index is referred as J this is a general way of defining the indices so here J is equal to 1 2 dot dot dot and then end so basically the I doesn’t change in the same row but the J changes and then of course we have slightly different in terms of I but then the same for J for our second equation so here I is equal to 2 and then J is again equal to one and then two dot dot dot and then n and then here up to for the last equation our I is equal to M and then our J is again equal to one till two dot dot dot so you might notice that I was looking at this from the row perspective so I was saying pair equation or pair Row the I doesn’t change but then the J stays the same and then it is either one two up to n but the set is the same so is it contains all these different elements here so one one two and then n but it contains all these different real numbers going from one till n because we are combining and we are creating this combination the sum of all this values a11 and then X1 a12 X2 A1 n xn and another thing that you can also notice here is that here with the second index so with this J J is equal to 1 then here the x is corresponding index is also one when the J is equal to two then the ex’s corresponding index is also two and then here the same story and you will notice that while the coefficient contains two indices 1 one 1 2 or 1 n which are the two indices for the coefficients for the unknowns we got just single index which goes from one till n so basically for a for the coefficients so I let me write with the right color so I can be one 2 all the way to m whereas in case of J it can be 1 2 all the way to n and the indices are basically used to help us to keep track of in which row we are and what is the um variable that the coefficient belongs to because knowing this second Index this helps us to understand that we are dealing with a coefficient that corresponds to this first unknown the first variable X1 and then the same holds in here as you can see in here and in here we are dealing with the same variable X1 therefore the second index the index J is then the same B both in the first equation and in the second one in both cases it’s equal to one okay so now when we are clear on that let’s also understand this high level concept because you will see this system of linear systems this m equations and N unknowns appearing a lot not only in terms of calculating and finding the solution to this linear system but this actually has a very common application ation when it comes to um running regression linear regression specifically and one thing that you can notice here is that here we got also this B1 B2 up to BM and you will notice that here the index also uh goes from one but then this time to M so when it comes to the rows we have M rows or M equations therefore we also expect when it comes to Counting from the top that at the bottom we will see an M whereas if we count from this side so kind of like imagine it like a column then we see that it goes from one till n so those are common observations and reference to um number of observations and number of uh features that you will see in your data when dealing with data analysis or modeling data so just this uh just keep those things in mind this uh abbrevation of M and then n m equations n unknowns because this will become very handy and the same also holds for this indexing just to keep in mind that this I and this J what those indices are and how for instance the first you know the I the first index changes when we go from up to the bottom and how the second index J goes and changes when we go from left to the right when we go through the columns but we are going to see this also in the uh upcoming slides so uh we can we will have time to practice it so um this is what we are calling a coefficient labeling the coefficient uh a i j so this thing in a linear system they are labeled where the first index represents the row and the second index denotes the column so when we see a i j we know that this refers to the row and the J refers to the column so this is something that we use in order to understand where exactly in our metrix something that we can we will see very soon where exactly our unit or our member that is part of our Matrix where exactly is that located in which row and in which column the systematic labeling is super important because this helps us to keep the structure and this helps us to understand uh what does this uh coefficient represent what what is this row that it belongs and what is the column it belongs so for which equation and for which unknown we have already solved the problem that say so we can know what this uh coefficient represents so before moving on on to the actual linear systems and this definition of matrices let’s quickly understand this distinction between homogeneous and non-homogeneous because this will help us to also get an understanding how we can solve a system of linear systems so a system is homogeneous if all the constant terms b i are zero otherwise it’s non homogeneous use so identifying this helps us to really understand nature of the solution set that we need to get and to understand what kind of strategy we need to use in order to solve this problem now what do I mean by bi we just saw that we had this system of M equations with n unknowns and we saw that that we have in the right hand side this B1 B2 up to BM which means that we had this m different equations with n different unknowns and to find a solution to the system it means finding this values corresponding to X1 X1 here X2 X2 xn so basically finding the set of X1 X2 up to xn that solves this problem and for us to know how to to solve this problem we need to know whether this B1 is equal to Zer or not this B2 is equal to Z or not and then this BM is equal to zero or not this is very similar to this idea of solving any sorts of um problems that contain unknowns for instance if we have three x is equal to let’s say five solving this is entirely different than if we know that the Tre X is equal to zero so this is a super simplified version of course but the idea is the same knowing that this B1 B2 up to BM this R zero this gives us an idea how we can solve this problem and later on we will see this distinction between non homogeneous and homogeneous system and whenever this B so whenever this B1 B2 up to BM whenever these BS are zero then we are saying that the system is homogeneous and we need to solve a homogeneous system otherwise we are dealing with non-homogeneous system so this means that the bis are not all zero let’s now move on to the second module which is about the matrices so we are going to define the Matrix we are going to see the definition of it as well as the notation decide your rows columns Dimensions uh some of which we have already touched upon but we are going to uh go into the depth of it we are going to learn properly as well as we are going to see many examples then we are going to talk about Matrix types so here we will talk about identity Matrix diagonal matrices and also special type of matrices like matrices containing only zeros and only ones so by definition and a matrix is a rectangular array of real numbers there are array Ed in rows and in columns for example an M byn Matrix a can be represented as follows so let’s look into this definition and this reference to Matrix we call this Matrix or Matrix a and every Matrix it can be described by this rows and columns where where we always have this uh way of describing this Matrix always should be defined by the number of rows and number of columns so this is super important and let’s look into this specific Matrix so we have a matrix a and all these values they are members of this Matrix they form The Matrix and we already saw this labeling of a i j where we said that I is referred to the row so you might recall that those were all these equations that we got so this horizontal lines where I was equal to 1 I I was equal to two I was equal to three up to the point of I was equal to M and then we had this J so this thing and then J was referred to the columns and we had J was here one and then two and then three up to the point of n so one 2 3 and N this is exactly what you can see here so in this Matrix we got all these elements a11 is a number a12 is a number up to a1n is a number those are all real numbers and one thing that you can notice here is that here we got a11 so this is our first row and First Column here we got a12 this is our first row and second column and then we got up to the point of a1n actually let me just write this down even at a bigger scale such that I can make more notes so let’s assume we have this Matrix a and this Matrix a if I’m bigger and we got all these different elements so we start with our first row and here we have A1 1 so here the row that I will write with let’s say with blue the row is equal to one and then the column is one so this is Row one this is Row one row one and this is column one let me write it with red this is column one this is column two this is column three dot dot dot and this is column n and this is row two this is Row three dot dot dot and this is row M so in total I got M rows and N columns I will come to this notation that I’m putting here later for now let’s keep track of the rows and the columns to get a good understanding what this indices were about that we just learned so every time I will also mention this reference to a i j to keep track of this and also let me write it with the right colors so a i this is the row and J which is the column so all the elements I’m just defining by this a because it’s just a way to reference a part that comes from a matrix it’s a just common way to write the entire matrix by capital letter A whereas its members will will write with the um with the lower case a so this is Matrix Matrix a all right so here in the second row But First Column we got a 2 and then one because it is still in the First Column and then when it comes to this element we have here a the row is the first one because we are in the first row but then we are in the second column so this one should be two then we go on to the next next element in our first row so a 1 and then three and then dot dot dot and the last element is an a as we are still in the first row it will be one the I but then given we are in the last column the column index or the J will be equal to n because we got in total n in columns so we are now ready to go into the second row so here given that we already have our first element a21 this is in our second row and the First Column so the I is equal to here 2 and G is equal to 1 let’s now write down the element in the second draw a second colum as you might have already guessed I is equal to here 1 I is equal to here two sorry and then uh the J is equal to two and then we go on to the next element which is in the second row and the third column so it’s a the row index is two so I is equal to two and then the column index is three dot dot dot and then we got a as we are in the second row it is the I is = to 2 and as we are in the last column the J is equal to n now you might have already guessed when I was writing this down that whenever you are in the row and you move on to all the elements in the same Row the I so the row index it stays the same only you need to uh update the column index so here for instance you got one one one here also one so all the way down in the same row or one which logically makes sense because we are in the same row so the row index should not change but instead you should change the column index like here column one column two column three all the way to column n so those are our columns dot dotp so let me make this distinction and those are our rows as you can see so this kind of mentally helps us to understand why we are writing all these indices over time once you practice more with this this will become more natural really quickly remove this so now I will write the rest very quickly so as you might have already guessed we are in the third row so we have a Tre so everywhere I will just write down D Ace so First I write down the A and then the rows the row index will stay the same as I in the same row but then I will increase the columns gradually so we are in the column one and then column two column three up to the column n so now the remaining stuff you can actually write down yourself to just practice let’s now move on onto the last row and last column so in the last row we got a a a up to here and in the last row the uh row index is M which means that here I need to have M M M everywhere I need to have M and then the column index is 1 2 3 all the way to n so this last column is very interesting too you can see here that we have the opposite of what we have here because in the last column we see that the uh column index is the same so it is everywhere n Only the first index the index of the row it changes it goes from 1 2 three up to M which is of course logical because we said that in the last column if we are looking it from the perspective of column so all these values this A’s so the all the ends they are logical because they we are in the last column we are in the same column but then the row changes here we are in the row one here we are in the row two Row three of two row M therefore we have also at the end a m n now let’s talk about this idea of MN we said that our Matrix a has M as a number of rows and n as a number of columns which you can see by the way also here so we always refer the dimension of a matrix so the dimension dimension of Matrix a by these two numbers so first we always write down the number of rows in this case M then as the second element we are writing the number of columns in this case n we are always putting this small X in between to kind of emphasize M by n Matrix and we most of the time use the square braces to Showcase that we are dealing with Dimension and in this case we are saying the dimension of Matrix a is equal to M byn so we are dealing with M byn Matrix this is a common convention used in linear algebra and Mathematics General but also used in data science uh in machine learning artificial intelligence so whenever you are dealing with matrices a it is a common convention to talk about this idea of dimensions and the idea of Dimensions is super important when it comes to the idea of multiplication multiplying Vector with Matrix Matrix with Matrix so this dot product Dimensions play a central rle in here so keep this one in mind once we uh get to the point of that products this one will become very handy so let’s now look into a specific example where we see simple Matrix a so in this case you can see that we are dealing with a matrix that has a 2×3 Dimensions so like we just learned 2×3 means that we got two rows and three columns that’s something that you can also see here very quickly so you have a small Matrix on the small matrix it’s really easy to actually count so you can see that we got Row one and row two and we got column one column two and column three so this basically confirms these Dimensions therefore we are also saying that we have a 2 by three Matrix and like usual we first write down the number of rows and then the number of columns you can see here that here we have this elements for our Matrix so a is equal to 1 2 3 for the first row and then 4 five6 for the second row so from this actually I think it’s a good exercise to just uh verify our understanding of indices and from this um we can write down that for instance all these different elements uh like A1 1 is equal to 1 A1 2 which means that we are in the first row and in the second column so we have this element is equal two two and then we got a and then one Tre so we are in the third column so this one is equal to three and then a 21 is equal to 4 a 22 is equal to 5 and then a 23 is equal to six so this is actually a good way to practice our understanding of IND is our understanding of this Matrix structure and the understanding of dimension of the Matrix which in this case is 2×3 so this is yet another different definition of a matrix structure when it comes to the rows comms and dimensions so this is exactly what we I just spoke about on our example and let’s just quickly look at the formal definition so the rows of a matrix are the horizontal lines of the of the entries while the comms are the vertical lines so basically it’s saying those are let me remove this so the rows are the horizontal line and the columns are those vertical lines those are the columns this helps us to form these columns so col one COL two and colum three whereas this horizontal lines it helps us to create the rows so Row one and row two so then we have the dimensions of Matrix are given by the number of rows and columns it has so an M byn Matrix has M rows and N columns that’s something that we already saw so let’s now look into some special type of matrices one Matrix type is the identity Matrix so we saw before we had this Identity or unit Vector now we have identity Matrix so the two are quite similar so like before for when we had our unit vectors we had this for instance E1 in three dimension we had 1 z0 then we had our E2 which had 0 1 0 and then we had our E3 which was 0 01 so you might recall this about our identity vectors or we were calling it unit vectors you might notice very quickly that we have formed an identity Matrix i n which is a square Matrix with one on the diagonal and zeros elsewhere is basically a matrix that is built using those unit vectors so here we have E1 here we have E2 and here we have E3 so you can also see that this 3×3 Matrix because we got three rows and three columns so you can see that here we have on the diagonal so we call this diagonal on this diagonal we have all ones and in here outside of the diagonal they are all zeros and this is the definition of identity Matrix it is this i n Matrix where n is the dimension of a matrix and given that it’s a square Matrix it means that the dimension of it is n by n so all the rows so the number of rows is equal to the number of columns on the diagonal we have all this ones and everywhere else we got zeros and do note that we are forming this identity Matrix simply by combining these different uh unit vectors so like here E1 E2 and E3 so let me actually uh give you yet another example but of much higher Dimension so of this identity Matrix so let’s say we have I and then this I uh let us actually use this notation i n so let’s say we got i n what this means is that we got actually this large matrix it’s a square Matrix which means that it is n by n so it has n as the number of rows and n as number of columns so the dimension is n by n you got n as number of columns too because it’s a square and let us actually write down that how that Matrix looks like it’s a large Matrix matx the N is the size of that Matrix so here we got on the diagonal we got one here we got one here we got one dot dot dot up to the last point one and the index of this one here so this is the first row this the First Column basically and everything else is simply zero so here we got zero 0 0 dot dot dot Z here we got 0 0 all the way down to zero here also Z all the way down to zero and then here also zero so everywhere here and here we all got zeros only on this diagonal we actually got once so basically by using our common notation we can say that in the DI in the identity Matrix we got A1 1 = to a 22 = to a33 equal to all the way to a NN equal to 1 and then when it comes down to the rest of the cases so all the other observations let’s say a 21 a 31 or a 41 anything so anything that is not um a11 or a22 anything that is not on the diagonal it is simply equal to zero we also say in those cases that a i j is equal to 1 if I is equal to to J because then it means that we are talking about item that is on diagonal because both the row index is equal to the column index otherwise the a i j is equal to Zer if I is not equal to J so this is in the nutshell how a large identity Matrix in general can be defined so let’s now move on to another type of Matrix which is the diagonal matrix so by definition a diagonal matrix is a matrix where all of diagonal elements are zero so what does this mean we just saw um example of a diagonal matrix which was our identity Matrix because identity Matrix is an example of a diagonal matrix and what do I mean by that that in our just seen example we saw that only on the diagonal we had all these nonzero elements but the rest were all zeros so all the of diagonal elements were zeros like in here and in here exactly the same holds for the diagonal matrices only unlike in the identity Matrix we no longer need to have this diagonal elements equal to one those can be any other numbers so as long as we have this um elements D1 D2 D3 that are not zeros but then off the diagonal numbers so all these elements they are zero then we are dealing with the diagonal matrix so in this case we got a 3X3 diagonal matrix because we have uh three rows and three columns and here we can see that the um the first so the a11 the first element from the first draw First Column is equal to D1 so a 22 is equal to D2 and then a33 is equal to D3 so D1 D2 and D3 those are all so D1 D2 and D Tre those are all real numbers now when it comes to the uh this numbers for example it can be that D is let’s say two 2 5 6 on diagonal then we have those zeros this is a diagonal matrix it can also be that D is equal to minus 3 and then 0 0 and then 5 8 and then here we have zeros so again we have on the diagonal all these elements and the off diagonal elements so if all the off diagonal elements are zero then we are dealing with diagonal matrix and if you are wondering well what happens if only the diagonal we got zeros do we still have a diagonal matrix it’s actually a great question but yes indeed we are dealing with diagonal matrix as long as all the off diagonal elements are zero so for instance if we got D is equal to here we have zero here we have 0 0 0 and and then 7 and then 0 and then 8 and then 0 0 so we got this off diagonal elements so here are the diagonal elements and all the off diagonal elements are those given that all the of diagonal elements are zero which is the definition of the diagonal matrix then we can say that our D Matrix in here is indeed a diagonal matrix let’s now look into yet another type of Matrix which is a special type of Matrix and it’s called one Matrix so by definition a one’s Matrix is denoted by 1 M1 so you can see here and here it mentions the dimension of it so the number of rows and number of columns and it’s a matrix in which all the elements are one so this is a very unique Matrix we often use it during the programming so in data science data analytics but also in um uh when creating like data structures when designing algorithms this becomes very handy and this idea of one’s Matrix is that all the elements are just one it means that if we want to create a placeholder in such way that we can then multiply any number in here with some other number and get that number then it can be done very easily because we know that when we multiply y a number with one then we get that number so a * 1 is = a x * 1 is = to X now this is exactly this property exactly is what motivates us to create and to have this type of ones matrices it means that we are defining matrix by its Dimension so it is M by n and here the m is equal to 2 and then n is equal to three because we got two rows and three columns but you can see that all the elements are the same and they are equal to one so a11 is equal to a 1 2 is equal to a 1 3 is equal to a uh 21 and is equal to a 22 and a 23 and they are all equal to one and this is the definition of one’s Matrix you can have um On’s Matrix of the size 4 by 10 one mat Matrix of the size thousand let’s say 10,000 by 100 Etc so any number any real number so M and then n are real numbers you can use in order to create this large M by n1’s matrix let’s now look into our final special type of Matrix before moving on onto the next module which is about zero matrices so similar to this one’s Matrix a zero Matrix denoted by 0 m by N is a matrix in which all the elements are the same with the one difference that this time all the elements are equal to zero so in the once Matrix all the elements were ones but in the zero Matrix all the elements are zero this type of matrices become very handy also during the programming creating um different algorithms during design in coding um but for slightly different purposes usually we create the zero matrices as a placeholder such that in the beginning we can have this uh tuples or we can have this um uh arrays or nested Loops um that we want to perform and then gradually add these values to the existing Mt array so if we create this zero Matrix and um this is a placeholder then next time we can always add on this this new data that we get and then we know that zero plus a number is always equal to number which means that once we have this updated information of a we can add this to the zero and we will then have this new updated information in our system therefore the zero Matrix is often used as a way to uh have this placeholder with the provided Dimension where we can always add new information and the information can be updated so in this specific case we got um a zero Matrix that has two rows and three columns so you can see two rows and three columns so m is equal to two and then n is equal to three three perfect so we are done with module two and now we are ready to go on to our next module which is the core Matrix operations so when when it comes to matrices we often perform Matrix additions metrix subtraction but also Matrix um a scalar multiplication of this Matrix so multiplying Matrix with a scalar and then Matrix um multiplication just in general so taking two matrices and multiplying them we are going to look into this concept in detail we are going to see many examples like before we are going to dive deeper into this such that we lay the ground on uh two to the next module which is solving a system of M equations with n unknown so solving this General U linear system so for the beginning uh we will be looking into this Matrix operations where we are adding or subtracting matrices so by definition the sum of two matrices A and B of the same dimensions is obtained by adding their corresponding elements so by taking the element i j from both matrices and adding them to each other so in this case you can see that Matrix A and B are here and uh the uh definition says we just simply need to take the corresponding elements corresponding elements from the row I and the column J take them add them and this will become an element in our final um Matrix because when we are adding two matrices of the same size the result is yet another Matrix so we will use the Matrix a to add to Matrix B and this will give us a matrix A + B and this IJ simply refers to the indices corresponding to the row and the column we will look into an example in a bit and this will make much more sense and the same holds also for the difference so by definition the difference of the two matrices A and B of the same dimensions is obtained by subtracting their corresponding Elements which means that in order to obtain this Matrix a minus B this is a new Matrix we simply need to look for each element so we are going to index them for a row I and J we are going to do this pairwise element wise subtractions we are going to see what is that element corresponding to the row I and column G in The Matrix a which we say is a i j we are going to subtract from this the element in the row I and column G that comes from Matrix B and this will give us our new Matrix which is a minus B so let’s now look into an example in this Matrix Matrix um uh a and Matrix B are used and Matrix a is of the size 3×3 Matrix 3 Matrix B is of the size 3 by 3 in order to obtain a + b what we are doing is that we are performing element wise additions now let’s verify this so what we are doing here is that we are saying a plus b let me actually get a larger area here so let’s say we have the two matrices I want to add the two in such way that we everything one by one such that this idea of a plus b and addition of the matrices will make sense so we want to find out a plus b for that what we are going to do is that we are going to make use of this definition that A + B and then I J is equal to a i j + b i which is a fancy way or mathematical way or describing that for each element we need to go and look for the row I and column J and take that element from the um column from that uh Matrix a and from The Matrix B so this means that for a plus b this is going to be a matrix that will have the same number of rows and the same number of columns as two matrices because both A and B are 3×3 which means also their sum is going to be 3×3 so this going to be 3×3 and here we are going to do so we are going to take for the first row and the First Column so for a plus b 1 one so first row and First Column we need to go to the first row and First Column of Matrix a and the first row and First Column of Matrix B and we need to add these two elements so we need to do 1 + 1 and then we need to go on to the second column so the first row and the second column which means that we need to be here in both matrices so here we have 0 + 2 and then we got 2 + 3 and then we got 0 + 0 so you can see it in here and then we have 1 + 0 and then we have 3 + 1 0 + 1 and and then 0 + 2 and then 1 + 3 which gives us so 1 + 1 is = to 2 0 + 2 is = to 2 and then 2 + 3 is = 5 0 + 0 is = 0 0 + 1 is = to 1 1 + 0 is = to 1 0 + 2 is = 2 and then 3 + 1 is = 4 1 + 3 is = 4 which means that our A + B is equal to this Matrix that we got in here so you can see that we are getting exactly what we uh what we have here only we have done it manually one by one so the same idea holds exactly when we have a minus B only instead of adding you will have to do here minuses so minus minus so everywhere minus so 1 – 1 0 – 2 2 – 3 Etc so let’s look into another addition so in this case by definition it is defined as this element wise uh of the adding of the two matrices here the only difference in this definition is that it’s saying it’s calling this a plus b as C so this new Matrix that we are getting as a result of adding a to B it’s calling C so basically it’s the same calling this Matrix a c you will see also this type of definitions so in this case The Matrix C is equal to a plus b which basically means that for each row with index I and with each column with index J go and look for row I and index J take the corresponding elements from Matrix a and Matrix B add them in order to get that corresponding element in our new Matrix C and you can see that in this example there’s EXA exactly what we are doing we have a we have B we are taking this element and this one so 1 + 1 we are getting here two and then 0 + 2 we are getting two here 2 + 3 is 5 and then 0 + 0 is equal to 0 1 + 0 is = to 1 and then 3 + 1 is equal to 4 so now we already go to the next topic which is about scaler multiplication of a matrix so by definition scalar multiplication of a matrix a by scalar Alpha results in new Matrix where each entry of a is multiplied by Alpha the idea of scal multiplication matrices is actually quite similar to this idea of scale multiplication in vectors so uh we have already seen in the lecture of the vector multiplication that when we were having the scaler C and we had this Vector a then uh when we are multiplying C which is a real number with Vector a then we simply need to take all the elements of vector a so A1 A2 all the way down to a n and we need to multiply them by this same scaler so see this is what we were doing with vectors and that’s exactly the idea behind matrices and when uh doing the scalar multiplication of matrices only instead of multiplying in only just one vector with the scaler C now we need to apply this to all the rows and all the comms so here we got this one column and Matrix is simply a combination of multiple vectors which means that we need to multiply all these elements of all the vectors of all the columns in this Matrix so let’s actually look into specific example so in this case we have a matrix a and and this Matrix a is this thing and we have a scaler which is three so in here our Alpha is equal to three or you can quote C or anything so you can see that when we are scaling The Matrix with a scaler in this case Tre with this Matrix what we are doing is that we are simply taking each of these elements and multiplying it with the scaler so 1 by 3 is 3 2x 3 is 6 3x is 9 and 4x 3 is 12 this is the idea behind this entire scale multiplication of a matrix in more general terms if we for instance have a matrix a so let’s actually look into a high level General example when we have a DA Matrix M by n so we got M rows and N columns and we want to get a skelet multiplication of this Matrix and um scalar that we have here as in our definition it is defined by this alpha alpha is just a number you can go C you can go B anything so in this case our scalar alpha alpha is coming from R so it’s a real number so Alpha time a is then simply equal to to this new Matrix where all of these elements are simply multiplied by this scum so I will just take over all these values H1 up to a M1 and then A1 2 a 22 all the way down to a M2 and then let me also add the last column just for fun here a 2 N and then here a m and so here this new scaled M multiplies so scaled uh Matrix a so Alpha * a is simply equal to Alpha time all these elements are simply multiplied by this scale it is as simple as that so that’s the simple idea behind uh metrix uh scaling so when you are doing scalar multiplication of this Matrix you simply take all the values and you multiply them element by element perir row and per column by that single scaler Alpha do note that you are multiplying them all without exclusion with exactly the same number which is that Alpha so let’s all look into the definition of matrix multiplication so here we are no longer multiplying a matrix with a scalar but we are multiplying Matrix with a matrix so the product of an M by n Matrix a and an N by P Matrix B results in an M by P Matrix C where each entry cig is computed as the dotproduct of the each Road of a and the Jade column of B now what does this mean firstly let’s look and unpack this part of the definition so we got Matrix a that is M by n and then we got Matrix B which is n by P what this means is that in this case Matrix a has M rows and N columns and Matrix B has n rows and P cups so this is then simply the dimension dimensions of the two matrices so then it’s saying that by definition the product of these two matrices so the product of A and B the product of the two B is equal to toce Matrix C and each entry c i j so c i j is computed as the dotproduct of the each row of a and the Jade column of B now this part might seem bit difficult but once we look into the actual example and we illustrate this on our common high level General expressions of Matrix a b and their multiplication this will make much more sense for now before coming to this one I just wanted to refresh our memory on one thing I said before when discussing also this idea of improving uh this uh different properties of vectors that when we want to multiply a vector with a matrix or Matrix with Matrix or vector with a vector we need to ensure that from the first element the number of columns is equal to the number of rows of the second element this is also very important for this specific case and just in general for matrix multiplication so you can notice here that the number of comms here is equal to the number of rows in here and the order is very important so in case of matrix multiplication the order is really important which means that if you have a matrix a and you want to multiply it with the Matrix B then the number of columns of a should be equal to the number of rows of B otherwise you cannot multiply those two matrices with each other so in case you got a matrix a that doesn’t have the same number of columns as the rows of number of the Matrix B then there are some alternative things that you can do including this idea of the transpose that we saw also doing when Computing the dot product between this Vector a and Vector B that’s something that we also do in programming when we are dealing with this Matrix and we want to compute this relationship between two matrices but the number of columns of one of the first one is not equal to the number of rows of the second one we are simply uh manipulating this matrices or removing some data if that’s not hurting our problem maybe uh flipping so transposing our Matrix or applying any other source of operation to it to ensure that the two matrixes that we are multiplying with each other the first one’s number of columns is equal to the second and once’s number of rows so that’s just the low and that’s something that you should follow if you want to multiply these two matrices all right so now let’s move on onto this idea of multiplying and Dot product let’s look into a specific example and this will um help us to understand this process better so before doing that I just want to quickly show you this general idea so if we have a matrix a that is M by n which means that it looks something like this like A1 1 a 21 up to the point of a M1 and then here we got let’s say a one 2 a 22 up to the point of a M2 and then at the end we got a MN and here we got A1 n so let me also add this one 2 N and we got a matrix B this Matrix B is n by P so it has n rows and P columns so we are fine in terms of Dimension here and we got here b11 B21 up to the point of b m sorry BN in this case let’s not confuse the letters so B N1 B1 2 B 22 up to the point of b n 2 because n now is the number of rows for Matrix B unlike for the Matrix a up to b 1 p and here b 2 p and here after to the point of B and then n p this is the last element in order to perform a multiplication between these two matrices so to obtain a matrix C which is equal to a * B what we need to do is we simply need to take pair case so pair Row for the row I for instance we need to take this element so this row and we need to multiply it with this so we need to find a dot product between this row and this column then we need to move on on to the next one and then for the second element we will then take this row and we will multiply it with this one so this is then something that we need to do in order to obtain these elements and you might have already noticed that we got this m by n and n by P so you might have already guessed what will be the dimension of the C if we got that the dimension of a is equal to M by n and the dimension of B is equal 2 and by P then the results Matrix after M multiplying the two of Matrix c will be will be having a number of rows equal to this and the number of col equal to this so This middle part basically disappears and the number of rows of the first Matrix will be then the number of rows of this result Matrix C and the number of columns of the second Matrix so Matrix B will then be our final number of comms so we will then have a matrix C that will have a dimension so Dimension so dimension of C will then be equal to M by P so we will have M rows and P columns so how we are going to compute this so for c i j which means row I and column J let’s look into the definition of it it’s saying c i J is computed as a dotproduct of the each row and the J column so each row from A and J column of B what is the each Road of a the each Road of a is somewhere here so each Road of a it is uh the A and then I one then a and then I2 and then a and then I3 dot dot dot and then a i and then we got in total n columns n and we always do the transpose right when Computing this um dot product so we then take the transpose so we take this row row I and we multiply it so we do the dot product between this one this this is the a i and the B J this is column J it is somewhere here so it is B and then we got the first element which is one and then J and then B 2J B 3j dot dot dot up to B and then in total we got n rows in B so n and then the J is the column so it stays the same so this is then the dot product between e row that comes from Matrix a and the J column that comes from Matrix P so it’s always like that actually so we always take row by row so we take this different so every time we take just a row and we multiply with the corresponding column and then we get the dot product between this row that comes from the first Matrix and then the column that comes from the second Matrix in that specific order in order to get our DOT product and that specific volume and what is this amount actually so when we calculate this dot product you can quickly see that we have a i1 * by B1 J plus a I2 * b 2 J and then dot dot dot a i n multiplied by b n g and this new Matrix c will then have all this so C11 C 21 and then c31 dot dot dot and then C the last row as the number of rows of C is m c m c here M so C and then here it will be 1 2 C 22 C3 and then two up to the point of cm and then two and then here the last coln will be C1 and then p is the number of coms in C so C1 p and then C 2 p and then C3 P dot dot dot and then c m and then P okay so this is what we get this is our final Matrix C when multiplying Matrix a and Matrix B so let me clean this up c is now if you want to find out what is C11 you can easily fill in this general formula that uh that we just calculated the I is equal to 1 and then J is equal to 1 and this will give you C11 by using this formula if you want to get the CM P then just fill in the I is equal to M and then J is equal to P in order to get this value CNP so you can already see the amount of calculations you need to do in order to get all these elements from these large matrices A and B let’s actually look into a simple example to clarify this so we have a matrix a here and Matrix B here and we want to do a multiplication of the two and we have just learned how to do it let’s actually do it one by one so we got a matrix a which is equal to 1 1 2 3 4 with Dimensions 2 by 2 then we got a matrix B which has values two Z and then one 2 so it is 2x two and I want to find what is c that is equal to a * B and I know already by looking at these Dimensions that c is going to be equal to 2 by 2 so you might recall that I said that when looking look at this final result the number of rows or the final um Matrix will be this so the number of rows of the initial Matrix a and then the number of columns of this final Vector c will be the number of vectors number of colums of this second Matrix B so two therefore I know already before even doing calculations that the uh product Matrix c equal to a * B is going to have a dimension 2x two let actually do a calculation to check this so C is then equal to a * B and it’s equal to 1 2 3 4 multiplied by 2 0 1 2 okay so I expect to have four different elements here here here and here so to obtain the C11 so it is C11 in here what I need to do is that I need to look at the first row and the first column in here so first row from a and the First Column of B and I’m doing the dotproduct which means 1 * 2 + 2 * 1 1 * 2 is 2 2 * 1 is 1 so here I’m getting 1 * 2 + 2 * 1 we which basically gives me 2 + 2 and that’s equal to 4 so here I’m just writing down 1 * 2 + 2 * 1 now when I want to get this value which is C12 this means that I want to get the first row and the second column and that’s exactly what I’m doing so I’m going back and I’m saying let’s look at the first row but this time we will look at the second column coming from the uh from The Matrix B so 1 * 0 * 0 + 2 * 2 and then I do the same only this time for the second row which means I’m picking this row and then this column so it is 3 * 2 + 4 * 1 and for the final element c22 I’m taking the second row and the second column which gives me three * 0 plus 4 * 2 now what does this gives me this gives me this 4×4 Matrix where 1 * 2 + 2 * 1 is 4 1 * 0 + 2 * 2 is 4 3 * 2 + 4 is = to 6 + 4 which is 10 and then 3 * 0 + 4 * 2 is = to 8 so let’s check 4 4 108 that’s exactly what we have here so as you could see here the idea is that every time to follow what element I’m looking for for the CJ and then I just go to the E rows from the first Matrix and the J’s column from the second Matrix and I do the dot product of the A and then I and then K let’s say so I’m going to the E Row from the first Matrix and I’m taking all the elements which means I don’t even need to mention this index it just means the entire each row coming from the Matrix a and then I’m doing the dot product between this row and the column that comes from the Matrix B which means B and then J which then will give me the cig so I’m looking at this and taking this multiplying this do product and this gives me the first element then the first row and then the second column which gives me the uh second element in the first row in my Matrix so this one and so on so hope this makes sense uh if it doesn’t make sure to reach out because it’s a very important concept and uh let’s also look into another example to make sure that we got this right so in this case as you can see we have another matrices so set of A and B matrices again 2x two a simple one and we want to know what is a so let’s say we call this C we already know C should be 2x 2 and what we are doing is basically for C11 we are saying let’s look at the first row so first row and the First Column coming from the second Matrix B and let’s do the dot product so 2 * 1 2 * 1 2 * 1 4 * 5 4 * 5 we get this and then when we want to find what is C oh what is C and then one two so in the first row but in the second element in our final Matrix so I is equal to 1 and J is equal to 2 it means we need to look at the first row from The Matrix a but this time the second column from from The Matrix B so it is 2x 3 2x 3 4 * 7 4 * 7 and this gives us a number 34 even if you calculate you can see that 2 * 1 is equal to 2 4 * 5 is 5 so 2 4 * 5 is 20 so 2 + 20 is 22 in here and then you can do the rest of calculations and this will be a good practice to see how we can do a basic matrix multiplication the idea is actually quite straight forward when it comes to multiplying it it just it comes with a practice when we see all this uh much bigger matrices so um this is another example I will leave this one to you to complete it just uh to keep in mind we always do uh so we always look at the dimension first in here 2 * 2 and 2 * 2 which gives me an impression already what I can expect the result will be 2 by two and when it comes to the uh cross elements just ensure to always look to the eth row and the jth column this comes from Matrix a and this comes from Matrix B take them compute the dotproduct and then you will find your C uh your final result let’s call it um kig J because in this case we have a matrix C already welcome to the module 4 of this course when we are talking about matrices and linear systems so in this module we are going to dive deeper into this uh idea of linear systems with matrices and solving linear systems using different techniques and specifically we are going to learn the uh concept behind solving linear systems using matrices named gausian elimination and gausian reduction welcome to the module one in this unit so in this uh case we are going to talk about algebraic lows for matrices we are going to disc discuss four different properties for matrices uh and the first one is the cumulative low for Matrix addition the associative low for matrices the distributive low for matrices both the left and the right one and then finally we’re going to talk about the scalar multiplication low for matrices so the algebraic laws for matrices they are like in case of real numbers like in case of vectors they help us to do different operations on these entities they are very similar to the real numbers and the vector cases where we for instance um so that if for instance A+ B uh is equal to B + C or a * um b + C is equal to a + a c those are uh all sorts of lows that we uh learn as part of high school pre-algebra and we have applied it to real numbers we know how helpful those can be and similar type of lows we have also for the matrices and we got in this case four different lows that we will be discussing the first one is what we are referring as associative low the second one is the distributive low the SEC the third one is the scalar multiplication low and the fourth one is the communative law for addition so these laws help us to do different metrix operations they help us to manipulate algebraically this metries and then uh this can help us to solve different sorts of problems including solving a system of linear equations so let’s start with the commutative low for Matrix addition so the Matrix addition is commutative um which means that a plus b is equal to B plus a so unlike the matrix multiplication that we have seen in the previous lessons uh where theorder did matter and we said that we um had to uh ensure that the number of columns of the first Matrix is equal to the number of rows of the second matx Matrix in case of addition that’s this is not the case so we should not care about the order whenever we want to add two matrices the other thing that we need to keep in mind though is that the two matrices needs to have the same size so I mean that both Matrix a and Matrix B need to have a dimension so dimension of Matrix a should be equal to dimension of Matrix B and let’s say should be equal to and M by n but for the rest we don’t really need to care uh which one we will put first will we put first a and then add the b or we will do the other way around so we will then First Take B and then we will add a so this is the idea behind commutative low for Matrix addition so first let’s look into all this uh lows and then we will also look into the corresponding examples so for this specific case it might actually also be helpful to write down the general formula which will um make sense out of this um low for the uh uh which is a communative low for the metrix additions so let’s say we got a matrix a which is M by n and this Matrix can be represented as a11 dot dot dot and a M1 so this is something that we saw time and time again so I’ll just quickly write it down the common notation for this and then here we have the last column which is a MN and this is the Matrix a then we got Matrix B which is again M by n and can be represented as b11 and then dot dot dot and then B M1 dot dot dot b 1 n dot dot dot b MN so the cumulative law says that A + B should be equal to B + a let’s check that whether this is the case let’s first compute this part and then we will do this one well the first one means that we get so A + B is and we remember how we add matrices right so we know that we just need to pick their corresponding elements and add them to each other so we get a11 plus b11 then dot dot dot and then a M1 Plus B M1 this is why also the it’s really important that they got um the same Dimension which means that they got exactly the same amount of elements or the same uh amount of columns and the same amount of rows um in terms of the uh Matrix size so then here we have a 1 n and then plus B1 n then dot dot dot and then a M1 and then plus b m here I need to put n we are in the last element of the Matrix so BMN and that is it this is our Matrix A + B let’s now look into the Matrix B+ a so what that amount is so The Matrix b + a will then be equal to b11 + A1 1 dot dot dot and then B M1 plus a M1 then dot dot dot and then b1n Plus A1 n then dot dot dot and then the last element will be B MN and then plus a MN so in here if we remember from the real numbers we know that A+ B is equal to b + a for instance if a is equal to 2 and then B is equal to 1 then a + b is = to 2 + 1 which is equal to 3 and then b + 1 is = to 1 + 2 and it’s equal to three so we know that indeed for the real numbers a + b is equal to B + a and making use of that property we can already state that B1 1 + a11 is equal to a11 + b11 and then the general case is that a i j plus b i j is equal to b i j plus a i j where I is the index of the rows and then J is the index of the columns from the coefficient labeling so using this property from the real numbers given that all these values in The Matrix are real numbers we can quickly see that the Matrix B+ a that we just got in here is equal to this Matrix a plus b which means that 1 is equal to B and this proves that a plus + B is equal to B + a this is the commutative property of the Matrix additions so the next law is the associative law for matrices which says that the in case of Matrix addition a plus b + C is equal to a + b + C so basically this time we go from here to adding one more element which is the third Matrix Matrix C so we are saying a plus b plus C is equal to a + B+ C so it doesn’t matter whether we will First Take The Matrix a and then B and then add them up and then we add Matrix C or if we first take the Matrix B and C add them up and then we add a to this sum it doesn’t matter we will see an example of this in a bit and then the uh second part of this associative law for matrices says that for matrix multiplication a * B * C is equal to a * B * C so again in terms of the um order when it comes to this specific multiplication so it doesn’t matter whether we will first multiply a by B and then by C or we will first multiply B by C and then we add the a at the end we will end up with the same amount so a * B and then * C is equal to B * C and then in the left hand side we add the a so a * B * C so this properties help us to add or multiply matrices without really worrying about this idea of grouping of the terms so we can always group them and perform all sorts of operations so this is this first property that we see in here let’s say we have this uh Matrix a matrix B and Matrix C so let’s prove that indeed the order doesn’t matter and dis associative property holes so let’s prove that so for that the first thing we need to do is to compute a plus b so this part so a plus b plus c what is that first I need to compute this part and then I will add C which is the second part so A + B is equal to my a is equal to 1 2 3 4 plus and my B is equal to 56 78 this is then equal to so 1 + 5 is equal to 6 2 + 6 is equal to 8 3 + 7 is equal to 10 and then 4 + 8 is equal to 12 this is my A + B this is the first part now the second part is then to add to this A + B this C this I can by the way also call some Matrix D so I can say that this is equal to D + C so let’s find out what is this amount so A+ b or what we’re referring as D is 6 8 10 12 we just calculated it in here I’m also adding now my Matrix C which is 911 10 12 so 9 10 11 12 what is this amount it is 6 + 9 is 15 8 + 10 is 18 10 + 11 is 21 12 + 12 is 24 this is my final Matrix so I have checked that D A + B + C is equal to 15 18 20 1 and 24 this is the first part let’s now go ahead and check whether this is equal to the second part which is this part so this is one this is two so this is then A + B + C as you can see it in here let’s now calculate that amount and like previously we will do it in an order so first we need to calculate this part and then the entire thing so B+ C is then equal to the B was 5 6 78 5 6 78 plus and the C was 9 10 11 12 9 10 11 12 what is the S much 5 + 9 is 14 6 + 10 is 16 7 + 11 is 18 and 8 + 12 is 20 this is the first amount let’s refer refer this as a d or we can even call it by some other letter let’s say k this is Matrix K so B plus C is k then the second part is to take this B+ C so B plus C which we have referred as K say K and then we are adding to this the A and specifically just to ensure that we stay with the same order I’m saying I will add from the left side the a to this Matrix K and this obviously means this is equal to so A + B + C this is what I’m referring by just uh in a more simpler notation I’m just using K in here so this is my B plus C or what I’m referring also as a k and this amount is equal to what is my a my a is 1 2 3 4 1 2 3 4 plus and what is B plus C we just calculated that that’s the K so 14 16 18 20 so 1 + 14 is 15 2 + 16 is 18 3 + 18 is 21 4 + 20 is 24 so we have learned that the a + B+ C is this vector now is this Vector equal to the A + B and then plus C well here we got this 15 18 21 24 15 18 21 24 so we have just proved that the first part is equal to second part which means that we have proved that indeed the order doesn’t matter and a plus b + C is equal to a + b + C so this calculation confirms that the both sides of this equations they are indeed equal and this confirms the associative low for the Matrix addition so let’s now look into the distributive law for matrices which says that Matrix addition and multiplication they satisfy the distributive property which means that if we have a left distribution a * b + C is equal to a + a and then in the right distribution we basically have the Matrix multiplying from the right from hence the name right distribution A + B * C is equal to a C + B C you might very quickly see and recognize from here that we have very similar actually exactly uh the same rule only for real numbers we know that a * b + C is equal to and then we open the parenthesis we say this is equal to this times this so AB plus this times this a c you can see that we have exactly the same here only in the capital letters so in the real numbers we have exactly the same low so the same we have also for our left distribution when it comes to Matrix additional multiplication and the same we have only with a different order here you can see the C so this one is basically uh with the different order instead of having the Matrix multiplied in the left here we have from the right and this is similar to the property that A + B * C is equal to C * a which is a c plus c * B which is b c to an example uh where we will prove that the distrib ative law for matrices um is indeed true and I have skipped deliberately the uh example for this one because uh this a b * C is equal to a * b c so the associative low for matrix multiplication it’s something that you can calculate for yourself using the same a b and c matrices only this includes multiplication of the two matrices and it’s something that we are going to to do as part of this example so instead of doing and redoing this multiplication I thought that it’s great to leave that for you as a practice and instead focus on bit more complex problem like this one that one way or the other includes the same matrix multiplication so I need to calculate the a * B in this case which means that by providing you this example I’m also including what is needed to do the previous example example only it would be a great way to practice the material for yourself so let’s now move into proving the distributive law for matrices so we got this matrices a b and c and here I’m going to apply matrix multiplication the same as that is needed for the previous uh case and here what we need to prove is that a * b + C is equal to AB * AC so this is the first part this is the second part so let’s go and calculate them separately so for the first one we need to calculate a * b + C which is then something that we can calculate by first doing the addition so we will first do the addition of matrices B and C and then once we are down with that we will then do a * b + C so that’s the second part so let’s go ahead and do that calculation so first we got B+ C what is B plus C B is 5678 5678 plus and the C is min-1 0 0 minus one so on the diagonal we got min-1 and minus one and then of diagonal lower and upper parts we got zero and what is this Matrix this is equal to 5 – 1 so 5 + – one is = to 4 6 + 0 is = 6 7 + 0 is = 7 and then 8 – 1 is = 7 this is our B plus C which we can refer also as Matrix D so let’s call this D which means that now we are interested in a * D so for this second part we need to take this Matrix a so a * D is then equal to we need to take the Matrix a which is 1 2 3 4 and we need to multiply it with this Matrix that we just got because this is the B plus C or the D that we were referring 4 6 77 okay so let me remove this part cuz we are going to need some space for this and let’s do this calculation this is 2x two and this is 2 by two I will do the calculations in here so we need to end up with the Matrix that is also 2x 2 because we know 2x 2 Matrix time 2x 2 we will pick this part so the number of rows and the number of columns of the second one this will be our resulting Matrix which is 2 by two all right so for the matrix multiplication we know that for the this element in the place of so one a or let’s call this Matrix we don’t even actually need to call this anything we can keep it simple so let’s say that we are in the first draw in the First Column so this is the first draw in the First Column for this what we need to do is we need to take the first row from the first Matrix so Matrix a and then the First Column of the Matrix D so this one and we need to do the dot product which means that we do basically 1 * 4 1 * 4+ 2 * 7 so for this element which is in the second row and the First Column we need to take the second row and First Column in here so we end up with 3 * 4 so 3 * 4 and then 4 * 7 so plus 4 * 7 The Dot product between this one and then this one so for this element which is in the first row and then second column of the final Matrix so first row and second column we need to pick the first row and second column and do a DOT product which means one 1 * 6 + 2 * 7 2 * 7 and then in here in this element we got the second column and second row so second row second column which means that we need to pick the second row and the second colum the dotproduct of the second show of Matrix a and the second column of Matrix D which is 3 * 6 + 4 * 7 4 * 7 so let’s quickly calculate what this amount is so this is the a * b + C basically and this Matrix is 1 + 4 is 4 2 * 7 is 14 4 + 14 is 18 1 * 6 is 6 2 * 7 is 14 and 6 + 14 is 20 3 * 4 is 12 4 * 7 is 28 which means that we got here 40 3 * 6 is 18 4 * 7 is 28 which means we got here 36 and 46 this is our final a * B+ C let’s now go ahead and calculate the second part so the second part says that we got a * b + a * C so a * b + a * C which means that first we need to do this calculation and then this one and then we need to add them to each other so let’s quickly then calculate what is a * B and then a * C and then add them to each other let me clean up some space in here we’re going to knit that then we write this one in a smaller format so this is equal to 18 20 40 and 46 and let me take over the second element which we still need to calculate which is a plus a c first we will do this and then this and then we will add them to each other so a * B is equal to 1 2 3 4 multiplied by 5 6 78 5 6 7 8 now follow following the same approach from the previous example when we calculate this Matrix I will then quickly calculate what is this a * B so in here we got first row and First Column so 1 * 5 + 2 * 7 so the dot product between the first row and the First Column from here now for this element here we got the second row and the First Column we need to take the second row Row in the First Column from here and we do the dot product which means 3 * 5 + 4 * 7 in here we got the first draw and second column so the first draw and second column which means that we need to have 1 * 6 + 2 * 8 then here we got the second row and then second column which means 3 * 6 + 4 * 8 and then this is equal to 1 * 5 is 5 2 * 7 is 14 so this is 19 1 * 6 is 6 2 * 8 is 16 6 + 16 is 22 in here 3 * 5 is 15 4 * 7 is 28 8 so this is then 33 and then 43 so 43 and in here we got 3 * 6 6 is 18 4 * 8 is 32 so we end up with 50 so hope I haven’t made any mistakes in the calculations so this is a * B so a * B is then equal to 1922 4350 let’s clean this piece and let’s move ahead to the second part of the calculation which is a Time C what is a * C well a * C is 1 2 3 4 1 2 3 4 multiplied by -1 0 0 -1 so here we are then getting -1 + 0 here we are getting – 3 + 0 here we have -1 + 0 so no so the first row and second column which is 0 – 2 and then in here we got the second row and the second column which is 0 – 4 which means that we end up with this Matrix and it’s equal to -1 – 3 then Min – 2 and then -4 which means that we are getting as a final step AB plus a which means 19 20 20 43 and then 50 then plus -1 – 2 – 3 – 4 and what is this 19 – 1 is 18 43 – 3 is 40 22 – 2 is 20 50 – 4 is 46 okay so we got that this amount AB + a is equal to 18 20 40 46 and as you can see already here this Matrix that we got in the previous calculation from one is equal to this Matrix that we got as part of second calculation which means that now we have proved that for this specific example indeed 1 is equal to 2 which means that a * b + C is equal to ab+ a there we go so let’s now look into another low which is the the scalar multiplication law for matrices so the scalar multiplication law for matrices says that if we got a scaler R and a matrix A and B then R * a * B is equal to R * a * B and is equal to a * R * B so here the r is just a scaler so it’s a number and then A and B are matrices and what this low basically says is that it doesn’t matter what in which stage you will do your matrix multiplication with the scaler if you have this external scalar you can first take the two matrices multiply them with each other so the A and then B and then multiply it with r or you can take the scalar R multiply with your first Matrix and then multiply with b or you can take your second Matrix multiply with the scaler and then multiply with a it doesn’t matter they will all result in the same Matrix so let us actually prove this by making use of our skills from matrix multiplication and scalar multiplication here I have picked up bit more uh Advanced example where uh a is 2 by3 and B is 3×3 in this way we will train our multiplication skills for matrices and at the same time we will also prove that the scalar multiplication law of matrices holds so let’s go ahead and do the multiplications so first we have a matrix a what is that Matrix Matrix a is 1 – one 2 so 1 – 1 and then 2 then we got 0 2 and then 1 which is 2 by 3 and then we got B which is equal to it is 3x 3 with elements 1 Z 1 1 2 0 one one and then 3 1 0 2 so it is 3 by 4 so it’s 3x 4 not 3x three but 3×4 Matrix now the final part that I need here is this which is R is equal to 2 the scalar value so R is equal to 2 so the first thing that I’m going to do is to calculate this amount which is R * a * B for that what I need to do is to First calculate this a * B so let me quickly go and calculate this for us e so given that the a has Dimension 2×3 and then B has a dimension 3×4 I can see that quickly that my Dimension criteria is satisfied the number of columns of a is equal to number of rows of B so that’s fine and then I know also know that the final dimension of a * B is going to be 2×4 so it’s going to be a 2×4 Matrix and how do I know that well because I I know that from our um all this problems that we have solved we have already seen that we always need to pick the number of rows of the First Column and the number of columns of the second uh Matrix in order to get the final Dimension which is 2×4 so let me then go ahead and do the calculation so we’re going to have a 2×4 Matrix let me write it even bigger so it’s going to be a 2×4 Matrix so for the first row and First Column I need to look in here the first row and the First Column which means I need to take one so it’s equal to 1 * 1 so plus 1 * 1 is 1 -1 * 2 is – 2 2 * 3 is 6 + 6 this is my first value and what is this amount it is equal to 1 – 3 – 1 1 and 6 – 1 is equal to 5 so this amount is five five so what is this amount well this is my second row and the First Column so I need to make use of second row and First Column which is equal to 0 * 1 is 0 2 * 2 is 4 and 1 * 3 is 3 4 + 3 is 7 so this value is seven we are ready to go on to the next column so column number two so then this time I need to look at the first row and second column so we are going to use this one so first we will use this first Row 1 * 0 is 0 – 1 * 0 is 0 0 + 0 is 0 and then 2 * 1 is the only non-zero element 2 * 1 is 2 so I already know that for my second column I got here two and what is this element well for this I need to look at the second row and second column so this thing so 0 * 0 is 0 2 * 0 is 0 1 * 1 is 1 which means that here I get a one let’s now move on to on uh towards the third column so in here first I need to look at the first row so 1 – one and two and then this time remove this I need to look at the third column because I’m here in the third column so 1 * 1 is 1 – 1 * 1 is 1 so here I got 1 – 1 and then 2 * 0 is 0 + 0 1 – 1 + 0 is 0 because those two cancel out this means that here in this element I got a zero and what about this this element where I need to look here in the second row and here I need to look at the third column 0 * 1 is 0 2 * 1 is 2 1 * 0 is 0 so 0 + 2 + 0 is equal to 2 so this is 2 and now we are left with the fourth column so for that I need to look in here so for the first row which means first row in here and then the fourth column here so first row in here and four column here 1 * 1 is 1 – 1 * 1 is 1 and then 2 * 2 is four which means that I end up with 1 minus one and then + 4 and what is this this two cancel out I end up with four which means that here I need to fill in four and what is this final element it is the second row in the fourth column so the second row in the fourth column 0 * 1 is 0 2 2 * 1 is 2 1 * 2 is 2 0 + 2 + 2 is = 4 so now we obtained that a * B is this 2 * 4 Matrix as we have expected so this is then equal to 5 2 04 and then 7 1 2 4 so then the next step would be to take the scaler R and multipied with a * B let me actually keep the colors consistent so a * B this is a * B so the only thing that I need to do is to take that in here and multiply this two with each of those elements so I will end up with the same size Matrix so 2x 4 only all these elements need to be multiplied with the scaler which means that I will get 5 * 2 is 10 2 * 2 is 4 0 * 2 is 0 4 * 2 is 8 and then 7 * 2 is 14 1 * 2 is 2 2 * 2 is 4 and then 4 * 2 is 8 so this is the result of the multiplication so this is the first part this is what we are referring as one so we have then checked in here that the r times actually we have already in here so I won’t be writing again so as part of the first section we have already seen that R * a * B is this Matrix let’s now move on to the next one which is calculating the second part so this is the first part this is the second and this is the third we have this already let’s now move on and calculate this one so for the second case so the second case what we want to calculate is R * a * B so it is R * a and then * B this is what we need to calculate so the first thing that we will do is to calculate this part and then to calculate the entire thing the second point so let’s go ahead and do that first we will take the A and then we will multiply all its elements by scaler two to get the R and then a this amount is equal 2 1 * 2 is = 2 – 1 * 2 is – 2 2 * 2 is = 4 0 * 2 is = 0 2 * 2 is = 4 2 * 1 is = to 2 this is R * a now in The Next Step so this was one the next step we need to take this amount this Matrix 2 – 2 4 04 2 and multiply it with 1 2 3 0 0 1 and then 1 1 0 and then 1 1 2 so basically the Matrix B let’s now move and work our way out with that one actually let me remove this from here and keep the space bit more clean R time a and I will be multiplying this with the Matrix 1 2 3 and then 0 0 1 and then 1 one 1 1 and then 0 2 well I know that this one is 2×3 and this one is 3x 4 which means that the result will be 2x 4 let’s now go ahead and calculate the Matrix which is equal with a dimension of 2x 4 well for the first row and First Column let me actually go and quickly do those calculations let’s now go ahead and do those calculations so we are going to have four columns as previously the dimension is going to be 2×4 so let’s do it column by column in here it means that we are in the row one and then column one so 2 * 1 is equal to 2 – 2 * 2 is -4 and then here we got 4 so 4 * 3 is 12 so we got 2 – 4 and then + 12 and what is this amount 2 – 4 is – 2 + 12 is 10 so here here we got 10 me remove this 10 this is the second row and the First Column which means we got 0 * 1 is 0 4 * 2 is 8 and 2 * 3 is 6 so 8 + 6 is equal to 14 so here we got 14 this is the first row and second column which means that we are looking at this row and second column this time so 2 * 0 is 0 – 2 * 0 is 0 the only thing that we care about is this one and this element which is 4 * 1 so this should be four let’s now do the same for the second row 0 * 0 is 0 4 * 0 is 0 0 + 0 is 0 which means we are left with 2 * 1 so here it comes two let’s Now do the third column so for the third column we got First Row 2 * 2 2 * 1 is 2 – 2 * 1 is – 2 and then 4 * 0 is 0 which means that here we get 0 because 2 – 2 + 0 is Z then we got the second row and third coln which is this row and then third column so 0 * 1 is 0 4 * 1 1 is 4 2 * 0 is 0 0 + 4 + 0 is 4 so this is four and then for the first row and then fourth column so it means that we need to look at this specific column the first row is 2 * 1 it is 2 – 2 * 1 is – 2 and then 4 * 2 is 8 so 2 – 2 + 8 is 8 and then finally for the second TR in the fourth column 0 * 1 is 0 4 * 1 is 4 2 * 2 is 4 4 + 4 is8 this is the final Matrix which means that this entire amount that we just calculated step by step this is equal to this Matrix in here okay so this is the second element let’s check whether the first element is equal to the first one so we see here 104 08 142 248 as you can see we are dealing with exactly the same Matrix which proves that indeed r * a * B is equal to R * a * B so this part we have already proven because we have seen that 1 is equal to two perfect so the only thing that is remaining is to calculate this third part and to see whether this is equal to this matrices because we have seen that the two of those are equal so the remaining thing that is left to prove this theorem is to calculate this third part let’s go ahead and do that so the third element says let’s first calculate the r * B and then multiply it by a so we need to calculate b r * B * a this is what we need to calculate which means first we need to calculate this and then we need to calculate the entire thing all right so let’s go ahead and do that so R * B is equal to so we need to multiply each of the elements of B by two so we end up with this Matrix 2 0 2 2 and then 2 * 2 is 4 2 * 0 is 0 and then 2 2 and then 2 * 3 is 6 2 * 1 is 2 2 * 0 is 0 2 * 2 is 4 this is that first Matrix let’s now go ahead and calculate the second part which is a * Matrix a so it is 1 – 1 2 and then 0 2 and then 1 multiplied by this Matrix which is 2 4 6 0 02 and then 2 2 0 and then 2 2 4 okay perfect so this is then what we need to calculate well this is 3 * 4 this is 2 * 3 which means the result should be 2 * 4 let’s go ahead and do those calculations this first amount will be the first row and the First Column dotproduct of those which means 1 * 2 is 2 – 1 * 4 is 4 – 4 and then 2 * 6 is 12 so here we got 2 – 4 + 12 and what is this amount well 2 – 4 is – 2 12 – 2 is = to 10 so this one this element is 10 then for the second show we need to look in here so 0 2 1 and the dotproduct of the one we the First Column so this thing and that is 0 * 2 is 0 2 * 4 is 8 and then 1 * 6 is 6 so what is 8 + 6 that is 14 and then for the first row and then the second column we need to look to the first row in here and then the second column in here and the DOT product of the two well 1 * 0 is 0 – 1 * 0 is 0 and then 2 * 2 is 4 so that’s what we are left with for and then for the second row and then the second column so this element we got 0 * 0 is 0 2 * 0 is 0 1 * 2 is 2 for the first row and the third column so we need to look in here 1 * 2 is 2 – 1 * 2 is – 2 and then 2 * 0 is 0 so we are left with zero 0 and then once we do the calculation for the second row we will see that we end up with 0 * 2 is 0 2 * 2 is 4 and then 1 * 0 is 0 so we end up with 4 and then here for the final column 1 * 2 is 2 -1 * 2 is – 2 and then 2 * 4 is 8 the first two cancel out and we end up with 8 and then for the second row and the fourth column we look into here again this time the second row 0 * 2 is 0 2 * 2 is 4 and 1 * 4 is 4 and then 4 + 4 is eight so if we look in here this is our third amount we will quickly see that again we have the same Matrix with exactly the same elements so now we have also proved this third part and we have seen that in all cases the r * a * B is equal to R * a * B is equal to a * R * B now we are ready to move on towards the second module in this unit which is about the determinants and their properties we are going to look into the uh determinants at high level we are going to Define them and going to understand why they matter and why they are important then we are going to see how we can calculate the determinants we are going to see the calculation for 2x two Matrix then 3×3 Matrix and then just in general how we can do it and then we are going to see the properties of determinants one by one and then finally we are going to see the determinant interpretation from the geometric perspective so when we visualize it using python so by definition the determinant is a scalar value that can be computed from the elements of a square Matrix so this important Square Matrix and encodes certain properties of the Matrix so the determinant provides a critical information about The Matrix such as whether it’s invertible and the volume scaling factor for the linear transformation it represents so we see that the uh concept of determinant is highly related to many other concept that we have seen before so first here it’s talking about the square Matrix then it’s talking about encoding certain properties so having the determinant it contains certain information that um is related to the properties of the system that that Matrix is is representing and then it provides critical information about the underlying Matrix because the determinant is calculated from a matrix we say the determinant of a matrix so it contains a critical information about that Matrix such as whether it’s invertible or not and this goes back to the concept of inverse we will see this once we learn the concept of determinant because the inverse calculation is dependent on the determinant but keep this thing in mind that the determinant contains information whether we can get um inverse from a matrix or not we will see this concept also in detail in the next section but for now we can remember that the determinant contains important information related to the invertibility of the Matrix so having an inverse or not and then it also contains information about the volume scaling factor for the linear transformation it represents so here we then go back to this concept of a x is equal to B and then knowing the determinant we can then comment on this volume scaling factor for this linear transformation that it represents so let’s go uh on to the next slide to find out bit more about the determinants and specifically how we can calculate the determinant in the mathematical terms when it comes to the 2x two Matrix because the uh determinant of a 2X two Matrix is quite straightforward so for 2x two Matrix a with this elements where a b c and d they are all real numbers the determinant which we Define by this de a so that is a short way of saying determinant and then in here we always write the Matrix of which we are Computing the determinant is then equal to and then we are taking this a * D so we are taking this diagonal elements a * D so they are on the diagonal and then we are subtracting from this this altitud remaining two elements of the diagonal so B * C and this gives us the determinant of a 2×2 matrix this is just a formula that you need to uh remember whenever you want to calculate the determinant of a matrix by hand manually so the calculation for larger matrices it involves bit more uh difficult uh calculation we will see also in a bit the uh determinant of a 3X3 Matrix It relies on the determinant of a 2×2 matrix and the idea is that every time we uh increase the dimension of our problem so let’s say we are in R4 then we will go back to the R3 and then given that R3 relies on the determinant of the underlying 2x two matrices anytime we increase the dimension we again go back to this idea of using 2x two matrices that form the entire Matrix in order to compute the determinant only when it this R4 R5 Etc so it becomes much more difficult to describe and to do it manually therefore there are other algorithms which we will see at the end of this course like uh the composition algorithms and factorization algorithm items that can be used in order to calculate the determinant of a matrix that has higher Dimension higher than the tree for instance but in this specific unit we are going to discuss both the calculation of the 2x two matrices determinant and the determinant of a 3X3 matrices and we will also see detailed examples of them so without further Ado let’s then go ahead and calculate the determinant of this 2×2 matrix so let’s now look into this specific example where we are calculating the determinant of this 2×2 matrix so this is the A and let’s keep in mind that this is the um uh a this is the uh B in this not in this uh way of writing the Matrix a so the uh letters corresponding of the uh elements of this Matrix a so this is the a this is the B and then this is the C this is the D and we said that the determinant that of a is equal to the diagonal elements so one * 4 minus the of diagonal Elements which is 2x 3 because we said that the definition of this determinant is that it’s equal to a * D and then minus B * C which is exactly what we are doing in here so if we calculate 1 * 4 is = to 4 and then 2 * 3 is = to 6 4 – 6 is equal to -2 therefore we say that the determinant of Matrix a is equal to Min – 2 let’s now go ahead and uh practice with calculation of determinants on two other matrices so in this case we are still in the two dimensional space so we have 2X two matrices we’ll first calculate the determinant for Matrix a so we see that we got this element 506 one and we know that by definition the determinant of the 2×2 matrix so that of Matrix is equal to a * d – B * C where the Matrix has the following form so we got a and then D in here and then B and the C in here so we see that this is basically our a this is our D this is our B and this is our C the way you can also see it is that those are the diagonal elements and those are the of diagonal elements so therefore it means that we can calculate the determinant of Matrix a by taking the 5 multiplying with one so it is 5 * 1 minus the of diagonal element which is 6 * 0 and this amount is equal to 5 – 0 and is equal to 5 let’s go ahead and also calculate the determinant of Matrix B we see here that on the diagonal we have this two elements one one and of the diagonal elements are both zero those two therefore we can calculate the determinant of this 2×2 matrix which is also sometimes referred as I2 so it is the identity Matrix because we got here the E1 and then E2 in the two dimensional space and the determinant of of the Matrix B using this definition is then equal to 1 * 1 – 0 * 0 so 1 * 1 – 0 * 0 and this is equal to one and this is actually a special case of determinant and later on we will see why it is so important to uh have this relationship of identity Matrix having a determinant and having it equal to one um and this relationship between determinant identity Matrix is something that we see also uh in the upcoming lesson so keep this one in mind so now when we are clear on how we can calculate the determinant for 2x two Matrix so this is quite simple and straightforward calculation by taking the diagonal elements a and then D and then subtracting from that from that product a * C we are subtracting the of diagonal elements products B * C we can then get our determinant and now when we are clear on that we are ready to go on to bit more advanced calculations which is calculating the determinant this time for the 3X3 Matrix so now we increase the um the dimension size and we go from R2 to R3 because now we have a 3X3 Matrix and by definition given a 3X3 Matrix a which has the following elements so a11 a21 a31 and then a12 a22 a32 so we have already seen this coefficient labeling this should look very familiar this is 3×3 Matrix 2 and the determinant of a matrix a denoted as that a is calculated using the formula and here we see the formula we are basically using the 2x two matrices that form this Matrix a in order to calculate the determinant of the 3X3 Matrix and how we are doing that well we are using this element and then this element and this element and every time we are hiding part of the Matrix so when we have for instance this a11 so for this first part we are saying well let’s hide the row and the column corresponding to this element which means that we need to hide this this uh row and this column and what is left is this 2x two Matrix we will calculate the determinant of this 2×2 matrix and we will multiply this with this element that we use in order to remove the corresponding row and column this will form the first element in here so you can see a11 which is a simple value so this this the um uh entry volume which is in the first draw and First Column a11 multiplied by the determinant of this Matrix so this Matrix so once we have that and we already know how we can calculate a determinant of a 2X two Matrix because this 2x two so taking the diagonal elements and then multiplying them together subtracting from that the of diagonal elements product now we are ready to go on to the next part of the calculation which is this time adding a minus here so you can see here this here is plus and then here is minus so we do here minus and for this second step what we need to do is kind of similar only this time the element that we will be using to understand how we can remove the row and the column so we will then dark it out it is this one a12 so then we will need to remove this column and this row and then the remaining Matrix which is this one this 2x two and here I mean a 21 a 31 and then a 23 and then a 33 this is the Matrix that you can see here remaining which means remove this one and then this one and then the remaining 2 by two Matrix is what you need to use in order to do your calculations so you can see that I got exactly the same in here and once again we are Computing the determinant of this Matrix we are multiplying this with this a12 element so this element and now we have also the second element in our calculation and then we go on to the next step which is a plus sign here let me use the same colors plus sign here and then we are using this time our final third element to understand which row and which column we need to dark out which is this element so we then remove the first row and the last column and this is then the Matrix the 2x two Matrix that we use in order to do our calculations so deter the determinant of this Matrix multiplied by the a13 so we could also use in the same manner this row or this row it really depends on the kind of values the the tip that um I will provide to you or the trick is that to always look for the Zer Zer values wherever I see Z zeros or I see one one I’m thinking that hey those same u values that um give me the most straightforward and easy calculations because if I have zeros in my C in my entry so if I got a zero here for instance 0 * any determinant is zero I don’t even then need to calculate the determinant right because then I know that I’m multiplying that determinant with zero therefore if I know that that entry for instance this row contains the majority uh of zero so it is 0 0 one then of course it’s a great uh row to pick to use this target elements so in that way I will then know that this is the row that I need to Target but if it is like that that for inance since I got a matrix 10 3 4 and here I got 0 1 0 and here I have 100 3 and 4 of course the easiest thing would be to not use this row but instead use this one so in that case I will then have this zero and zero as my target values which means that I will only need to calculate the determinant of a 2 x two Matrix this uh for this one for the two cases I don’t need to do because I know that the corresponding Target values the target elements from my Matrix will be zero so let me show you what I mean by that so if for instance I go for this second row and not the first one what I need to do is that I can calculate the determinant of a by taking the a21 this then will be my target I will then need to remove move this uh column and this row then I will need to do the determinant of A1 2 A1 3 a 3 2 a33 this is what then I need to do then the next thing I need to do is of course here I have a plus here I need to do minus because we always need to Interchange the values so here is a plus here is a minus here is a plus so I do PL a minus in here then I do the next element in my row which is this one let me use red color so a22 so I’m then doing a 22 multiply the determinant of so I’m re removing this row and this column a11 a13 and then a31 a33 and then the final part is of course as you might have already guessed is to look into this element so it is plus a 23 multiplied the determinant of let me actually write it down in here the determinant of a11 A1 2 and then a31 and then a32 so in this way basically independent of what row I will take as my leading row that I will do my calculations and I will just need to pick one row I can always get the same value for determinant of a but choosing intelligently which row to pick it will save you a lot of time and headache in terms of calculations because if you are dealing with a row that contains many zeros for instance you have 0 0 1 or 1 0 0 or even better 0 0 Z then you know automatically that you will need to calculate your DET the determinant once here also once and here you don’t even need to calculate it you know that you got zero here Z here Zer here so it’s automatically equal to zero so I hope this makes sense because this is a trick that usually you will not come across but this just helps you to save a lot of time uh when comes your calculation of your determinants in a 3X3 settings so in this case uh we have this um we now we have this definition and we know the tricks that we can use but I think it’s really uh helpful to go ahead and to solve a problem so basically this is the higher level summary of the steps that we just discussed um so the determinant of a 3X3 Matrix it simply involves multiplying the A1 1 by the determinant of the 2×2 matrix that that remains after excluding the row and column of a11 so what we did in here by doing this and subtracting the product of A1 2 and the determinant of its respective 2 two Matrix so this part and then adding the product of a13 and the determinant of its respective 2x two Matrix so this part and this signs alternate so it means first you always got the plus then you always get the minus and then the plus so they interchange you start with plus then you do the minus and then the plus so let’s go ahead and calculate the determinant of this Matrix so before even looking at the answer let’s actually go ahead and do that on this paper so we got a matrix a which is equal to 1 2 3 4 so basically from 1 till 9 1 2 3 4 6 4 5 6 and then 7 8 9 and for this 3×3 Matrix we need to calculate the determinant so the determinant of a the first thing that I’m seeing is that there are no rows with zeros or columns which means that I cannot use my uh trick and instead I will just need to go with let’s say the first R and it’s also convenient given that I got as scaler this values this much smaller values relatively to the other ones all right so first things first let’s go ahead and write down that formula so the determinant of a is equal to first we are going to take this one so our one one times and then we got determinant of and then we have this Matrix which is 5 6 8 and 9 this is our remaining Matrix then the next thing we need to do is to Interchange the size uh the the sign which is minus and then we got so the remaining Matrix is then determinant of 4 6 7 9 and then finally plus three times and then determinant of what do we have well this is the target so it is 4 5 7 8 right so let’s go and do those calculations quickly this is equal to 1 * the determinant of this is the diagonal element so 5 * it is 5 * 9 – 8 * 6 – 2 * 4 * 6 – 7 * 6 Sorry 4 * 9 so the diagonal elements 4 * 9 – 7 * 6 and + 3 * and then 4 * 8 – 5 * 7 this is equal to so 9 * 5 is = to 45 8 * 6 is = to 48 then- 2 * 4 * 9 is 36 7 * 6 is = 49 7 * 6 is = 42 + 3 * 4 * 8 is = 32 – 5 * 7 is = 35 so this is = to 1 * – 3 – 2 * and then here we got 36 – 42 so that’s – 6 + 3 * – 3 which is that equal to – 3 + 12 – 9 which is equal to Z so let’s check it indeed we got the right answer perfect so now when we are clear on how we can do this calculation let’s now go ahead and calculate yet another determinant of a 3X3 Matrix and this time I want to show you this uh simplified version by you making use of this trick that I uh specified so instead of using this first dra as an indicator I will be using the uh second row as my indicator one thing to keep in mind when making use of this trick is that when you start from the second row so from the even rows even rows second fourth or sixth then in those cas PES you need to flip the signs that you will be using so while in here you had the Sign Plus in the beginning then you got a minus and then a plus when doing all these calculations so you remember here we got plus minus plus when you start from the second row instead of first one you need to flip the order of this so you need to start with minus you have minus you got plus and then minus so knowing this trick it also means that you go One Step Beyond and you know how you need to intelligently uh reduce the time that you are spending on calculation uh calculation of the determinant but it also means that you need to be careful on knowing what kind of science you need to use because if you start from the first or you start with plus and then you do minus plus minus plus so knowing how to start you already already know how you can go on but when it comes to the second row so the even rows you need to start with the minus so you need to do minus plus minus plus dot dot dot all right so let’s now go ahead and use that technique in here so here I see that my first row doesn’t contain zeros but my second row does so this gives me indication that I can reduce the time that I spend on calculating the determinant at least one time because I didn’t no longer need to calculate that determinant so the determinant of B is then equals 2 I will then start with minus given that I’m going to use this rope and then I have 0er * so because this is my element the determinant the determinant of 2306 and then Plus then this time the second element Target element is this one so it’s four times and then we got determinant of 1 3 1 6 and then minus D 5 * so this five determinant of 1 2 1 Z and what is this amount it is equal to this I don’t need to calculate because I got a zero in here this this trick is all about this to not calculate the determinant too often and then this equal to four times 4 * determinant of this is 6 – 3 so 1 * 6 – 1 * 3 which is equal to 3 and then minus 5 * determinant of 1 2 1 0 which is 0 – 2 so this equal to 4 * 3 12 – 5 * – 2 which is equal to 12 + 10 and is equal to 22 let’s go ahead and check this and this is the more detailed and formal derivation so one uh interesting thing is that I calculated with my second row and in here in this slide you can see calculation with the first draw this is just a nice way of seeing the difference that you can do in here uh in this solution what we have is that we have manually calculated this first determinant to so in total three determinants but we again end up with the same determinant so independent what kind of row you will use in order to calculate your uh determinant of Matrix B you will all always end up with the um with the same similar volume unless you have made a mistaking your calculations so you just need to keep track of the uh rows that contain many zeros and you need to um be careful in terms of the signs that you need to use and the sign that you will need to start if you start with the first row then start with plus if you start with the second row then it is minus and then plus Etc so as you can see here it’s a plus and then minus and then Plus in my case I did with my second row therefore I started with minus all right so let’s now move on to the properties of determinance so the determinant of an identity Matrix is one that’s something that we have also seen when doing our calculations because we uh saw that in one specific case when we had this example so this Matrix B and the Matrix B was the identity 2 in two dimensional space we have calculated its determinant and we saw that it’s equal to one and this was not a coincidence because the determinant of identity matrices is always equal to one then the second property is that swapping two rows or Columns of a matrix changes the sign of its determinant so if you swap rows or columns in your Matrix so if you end up with Matrix A and B they are exactly the same only one swaps the two columns or two rows then you are changing the determinant of that Matrix uh the sign of that determinant but not devalue itself it means that if you got a and you got B and your a is equal to let’s say uh A1 and then B uh A2 and then A3 so it contains these columns and then Matrix B is equal to um let’s say A2 and then A1 A3 then and the determinant determinant of a will be equal to minus of the determinant of B you can also say determinant of B will then be equal to the minus determinant of a this is basically the idea of this property let’s now move on to the third property which says that if a matrix has a row or a column of Zer its determinant is zero so if you got a matrix a that contains these different values a11 H1 dot dot dot a n uh M1 and then here you got suddenly um column that contains all zeros and then the rest are nonzero even so in that case you know that your determinant is is equal to Z so for a specific example if you got for instance Matrix 1 0 2 0 0 3 13 then the determinant of this Matrix is equal to zero and otherwise if you got a matrix B that has a column of zeros so come that is entirely of zeros so let’s say here we have 1 one one and we have a a zero Vector here so we got in here 0 0 0 and then 3 4 five then given that we have here this zero Vector then the determinant of Matrix B is equal to zero and this actually straightforward to be seen from this calculations that we saw because if you do the uh if you pick this specific row and then you do 0o times determinant of the remaining Matrix 0 times determinant of the other Matrix and then plus so plus and then so minus and then plus and then minus 0 * determinant of the third Matrix it is obvious that 0 * a determinant is0 0 * determinant is 0 0 * determin is zero which means that you got a whole bunch of zeros to be added to each other or subtracted from each other this means that if you have a row or a column with zeros this already gives you an idea that your determinant is equal to zero you don’t even need to do calculations so the final property of determinants is that if a determinant of a product of matrices equals the product of their determinants so the determinant determinant of a b is equal to determinant of a multip by determinant of B this is basically what this property is about so let’s quickly go through examples to ensure that we are at the same page with all these properties and we can prove them so let’s say we have an identity Matrix n by n which is we are dealing with i n now according to this first propert T when we calculate the determinant of this Matrix so the determinant of i n is equal to 1 Let’s actually look at a specific example so here we got um identity um Matrix in the two dimensional space in the R2 and we can quickly calculate the determinant of this I2 and we can see that it is equal to this diagonal element so 1 by 1 minus 0 * U it’s actually something that we did as part of my uh previous examples so this equal to 1 – 0 and is equal to 1 one thing that I wanted to show you before moving on to the next example about the swapping rows is that when we are swapping some of the rows or some of the columns or two rows or two columns of Matrix a we are referring to this matrix by this notation so we add this not in here and we say that this is basically the manipulated version of Matrix a so if we have for instance Matrix a equals you a b and and c and those are vectors and then we are swapping two of the columns let’s say we are swapping this two we get B and then a and then C then this Matrix we are referring as a not this is just a matter of notation and we just learned it as part of the properties that the determinant of this new Matrix is equal to minus the determinant of a so if a matrix a has a row or column of zeros then the determinant of it is zero so let’s actually quickly look at this specific example in here we got a which is uh having a column of zeros and another column of B and D where B and D are real numbers so let’s prove that his determinant is actually equal to zero so the determinant of a 2X two Matrix we have already SE is equal to the diagonal elements so 0 * D minus the of diagonal elements which is 0 * B 0 * B and what is number * 0 is equal to 0 0us 0 * B is also 0 it’s equal to 0 therefore the determinant of a is equal to 0 so when it comes to the uh determinant of a product of matrices let’s prove that the determinant of a * B is equal to the determinant of a Time the determinant of B so therefore the first thing we need to do is to calculate this a * B let’s quickly go ahead and do that so let me add here this um blank file so a is equal to 1 2 3 3 and 4 B is equal to 5 6 78 and I want to prove that the determinant of a b is equal to determinant of a * determinant of B first I will be calculating this and then I will be calculating this so for the first one what I need to do is that first I need to calculate d a * B which is equal to 1 2 3 4times 5 6 7 8 and then this is equal 2 should be 2 by two so first I take this 1 * 5 is 5 2 * 7 is 14 14 + 5 is 19 then for this one I need to pick this row so 3 * 5 is 15 and then 4 * 7 is 28 so 15 + 28 is so there we have 33 43 so I got here 43 then I’m going on to the next column which is in this case 1 * 6 is 6 6 + 16 is 22 and now the second column 3 * 6 is 18 4 * 8 is 32 and this gives me 50 all right so now I have the 800 B then as the next step what I need to do is to calculate the determinant of this a * B which is equal to the determinant of this Matrix 19 22 43 50 that I just calculated and what is this amount the diagonal elements 19 * 50 – 43 * 22 19 * 50 is then equal to 950 and 43 * 22 is 946 which means that we end up with four this means that the determinant of the a * B is equal to 4 let’s quickly check what are the parts of the second amount so for that I need to calculate determinant of a which is equal to 1 * 4 – 2 * 3 1 * 4 is 4 3 * 2 is 6 so 4 – 6 is = – 2 determinant of B is equal to 5 * 8 which is equal to 40 and then 7 * 6 is equal to 42 and this is equal to Min – 2 and determinant of a times determinant of B is equal to – 2 * – 2 which is equal to 4 so we can see that now we just proved that the determinant of a * B is equal to 4 so we have seen that determinant of ab is equal to 4 and we see that that’s exactly the same as determinant a * determinant of B which is equal to four so we have just proven that the this equation indeed holes so the determinants they are not just um some calculations or some amounts but they are actually uh important concept and their interpretation um is highly relevant from geometric perspective so determinant have a geometric interpretation and the for example determinant of a 2X two uh Matrix or 3×3 Matrix they represent the area in case of 2x two or the volume in case of 3×3 Matrix uh of the parallelogram that they are forming so uh this is often referred as uh parallel uh piped um I hope I’m pronouncing this correctly and it’s formed by the con vectors of the Matrix so if we have for instance this uh Matrix a and then we have a b and then C and D we have this A and C which is the first vector and then B and D which is the second vector and the uh the two vectors they actually form a parallelogram um when it comes to the uh two dimensional space and the area that this uh parallelogram uh is forming that is equal to the determinant of this MRI so the determinant of this scalar value that summarizes this linear transformation that we describe by this Matrix because we saw that we had this a x is equal to B linear system that we were describing using this coefficient Matrix and this was our unknowns this was our variable and then this B was the um amount that we were uh putting this as equal to if B was equal to zero then we were solving the homogeneous system otherwise we had this non-homogeneous system and in the geometric terms the determinant of this Matrix a so the determinant of a um in case of 2x two space so in R2 um when we got two vectors basically in our Matrix a this is equal to the area that is spent by these vectors in the two dimensions space in a bit I will also show you specific example such that um we will be on the same page when it comes to this concept of parallelogram the determinant and those vectors that form the column um uh space of the uh Matrix a uh when it comes to the three dimensional space when we have R3 so we got 3×3 Matrix of a then the determinant of this Matrix a is it’s the volume that is um formed by these uh threedimensional vectors because unlike the two in R TR we got the three vectors that form the a let’s say this one this one and then this one and then here we can create this area covered by these three vectors and the area that is formed by these three vectors from a it is equal to the determinant of that Matrix a so in terms of the 3D it’s bit harder to uh visualize it but in uh case of the two-dimensional space I think this will help uh to improve our understanding of the determinants and make this interpretation uh from geometry uh from geometrical perspective so given the two vectors A and B in the two dimensional space the determinant of this Matrix uh is then equal to the um diagonal elements we already know minus the of diagonal elements right so we are also saying we have seen this notation already very often you will see this volume this is the absolute we already know this from high school this is the absolute volume because the determinant can also be a negative number we have seen – 20 or minus 2 and we know that the area cannot be a NE negative number therefore we are adding this absolute term here so knowing for example that we have this Matrix a which consists of the elements 3 2 and then 1 4 we know that the determinant of this a is equal to 3 * 4 12 – 1 * 2 it is 10 and the absolute value of it so absolute value of 10 is equal to 10 given that is positive and this is exactly what we have here and this is referred as the area of the parallelogram that the two vectors are forming and how does that look like in uh the uh coordinate space so this is the parallelogram that we were referring by and this area that is formed by this parallelogram is equal to the determinant of the a The Matrix a so one thing that we need to keep in mind is the definition of parallelogram which means that those two are parallel and they are the same so this and this lines those two are the same and then of course the same holes for those two they are parallel and they have the same um length therefore this figure in here this is what we are referring as parallelogram and those two vectors that we can see in here this one and this one they form this parallelogram and they are the two vectors that are part of the Matrix a hence if we got two vectors that the uh that come from The Matrix a so Matrix a and we got here this two vectors in a 2X two Matrix then the determinant of this Matrix is then describing the area that these two vectors are using or are spinning when creating this parallelogram so the determinants they play an important role in understanding the geometric properties of the spaces that uh spent uh by these vectors they provide valuable insights when it comes to the scaling effect effect of linear transformation the orientation and the um the locations of them in the coordinate system as well as the Practical applications in calculating areas in calculating volumes welcome to another unit in our fundamentals to linear algebra course where we are going to talk about Advanced linear algebra Concepts so uh in the first module we are going to talk about Vector spaces and the projections we are going to define the bases in a couple of examples of them we have already touched upon this concept briefly when we are calculating the basis of a no space and the basis of a comp space we are going to do a similar example in this case and then we are going to uh look into this concept of the uh standard bases for uh different spaces including the arum we’re going to to introduce the concept of projections what is the definition of projections what is the formula how we can calculate it we are going to look into detailed examples of them then we are going to talk about a concept of auton normal basis in this module we are going to introduce this concept then we are going to understand the orthogonality normalization we are going to then discuss a very important topic in linear algebra which is the gramme process we’re going to Define it we are going to see the overview the step by step process of applying grme uh algorithm then we are going to see an example of it and the calculations step by step and then we are going to talk about applications of auton normal basis the application of gram Smiths process and the importance of this auton normal basis this is the module one of this part so let’s first Define the basis a basis of a vector space is a set of all both linearly independent vectors that spend the entire Vector space every Vector in the space can be expressed as a unique linear combination of the basis vectors so there are a couple of parts in this definition they are really important and first thing that we need to uh mention here is this Vector space that says it is a set of linearly independent vectors that spend the entire Vector space this is very important because um here we are with the basis is simply this Vector space that is a set of linearly independent vectors which means that one of these vectors cannot be Rewritten as a linear combination of the other one so we have a larly independent vectors and they span the entire Vector spe space so for instance if we are in R2 then the basis of a vector space is then a set of linearly independent vectors that span this entire R2 so we do we then need to have four vectors forming a basis so let’s say we have a basis of vector space for us to say that this is the the basis of this Vector space let’s say in R2 we need to First say we need to First prove that these vectors this vectors are linearly independent and two they span the entire R2 which means that span of these vectors is equal to R2 we can actually be even more specific in a example of let’s say having a vectors A and B we can say that this set that we have here consisting of vectors A and B in R2 form the bases of a vector space if the first criteria is that a and b are linearly independent and the second criteria is is that those two vectors together they spend the entire Vector space of R2 which means that span of a and b Vector space is equal to R2 on more specific example and then the second part of this definition says that every vector in the space can be expressed as a unique linear combination of the basis vectors which means in our specific example when we had this A and B forming the bases of vector space this means that if we prove that this is indeed the basis of this Vector space then any combination every Vector let’s say a vector C that consists of this C1 and C2 elements that this Vector this random Vector from R2 C can be represented as a linear combination of these vectors A and B so let’s say we have a coefficient K1 time a plus K2 * B then here we are representing this random Vector c as a linear combination of these vectors A and B which form the basis of a vector space of this Vector space so we have previously spoken about the no space and Comm space so let’s now go ahead and do one more example when we are calculating the no space and the Comm space and then we are again calculating this concept of basis of vector space and B basis of the Comm space and then we will be uh finding the basis of a vector space uh with um R2 example so given that we have already looked into this concept the basis of Comm space and basis of no space I will try to uh go through this example bit more quickly to save time on more complex Concepts so let’s say we have an example of a matrix and that Matrix is a is equal to 1 2 3 6 this is our 2x 2 Matrix a and the first thing that I want to do is to understand look into my Matrix and understand whether I’m dealing with unique vectors or not and by unique I mean whether I’m dealing with two vectors that are linearly dependent or linearly independent this kind of inspection always helps us to save time when we are doing our calculation for the no space and for the Comm space and for the basis of no space and base of Comm space now here we can see that this our A1 the first Vector the first com Vector forming the Matrix a and this Vector is the hu another thing that uh we can notice here is that we can easily take the First Column A1 multiply it by two and get D A2 because 1 * 2 is 2 3 * 2 is 6 that is that 2 * A1 is equal to A2 which means that we can say that A1 and A2 are linearly dependent okay so seeing this and knowing this this can help us to quickly go through our calculations of the bases of the col space and the bases of a no space so let’s go ahead and first calculate what is the basis of no space of a so we have already learned that the um basis of a no space can be calculated when looking into the first no space so we we need to calculate the no space and then we need to calculate the basis of that no space so this means that we need to get the na and we have learned that in order to get the na we for that need to solve the a x is equal to zero problem and this x will give us the no space of a we have also learned that the no space of a is equal to the no space of R RF of a which means that using gausian reduction or gausian elimination we can quickly find the solution to this problem of a x is equal to Z and find this x this is simply solving a similar Pro problem only in this case the B so this is equal to zero because we are dealing with the homogeneous case I want do the calculation for this we have done a ton of examples when we were doing this step bystep calculation getting the uh argument Matrix of a and then doing all these different draw operations normalizations and then eliminations in order to uh get this uh complex Matrix a to the point of uh basic representation from which either we can visibly see the solution to the problem or we can at least simplify it and describe it as a linear combination of vectors in this case if you go ahead and solve this problem you will find that the x that solves the a x is equal to Z problem is unique and this x is equal to- 0.894 4 as the first element and then 0.447 as the second element this can be a good practice also to refresh um the memory when it comes to the gaion elimination and reduction the example itself is quite simple the a is just a 2×2 matrix um and um by performing couple of operations uh in terms of normalization and elimination you can find this X for your ax is equal to zero given that now we know what is the solution to ax equal to Z problem now we know what the no space is because in this case the all this help us to understand that the no space of a is then equal to the set the vector set where as part of this we got just single column which is minus 0.8 94 and 0.447 this is the no space this is the first part I will say it 1.1 and then 1.2 will be to get the bases basis of this na and we have just seen what is the definition of the bases so the basis of vector space is a set of linearly independent vectors that spend the entire Vector space therefore given that we got just this single Vector as a solution to our problem we can see then very quickly that the new space of a is based on this and then the basis of the no space is simply this entire set so knowing what the solution is to our homogeneous problem a is equal to Z so let me also write down in here then we know that the no space the N A is then equal 2D Vector minus 0.894 and 0.447 this is my Vector X that solve this a is to Z problem and this is simply the no space of a and given that we have calculated and we have got this unique solution to our problem we can say that any Vector in R2 can be represented as a linear combination of this Vector so 1.2 any Vector in R2 can be represented as linear combination combination of this Vector X therefore we are saying that the bases of no space of a is this entire set consisting of the single vector so this is about the basis of a no space let’s Now quickly look into the concept of the basis of a c space so the first thing we need to then uh get is the column space so to get the bases of CM space we need to get the ca first which is the Comm space of a and what is the Comm space of a the Comm space of a uh is the uh setle and the space of the vectors that we can see in here in this A1 and A2 is it’s quite straightforward so these two vectors they form the c space of this Matrix a so then the ca is simply the set of one three and then two six vectors this is A1 this is A2 now we have just seen in the beginning before even starting our calculations that A1 and A2 are linearly dependent because A2 can be right written as 2 * A1 so one of these vectors can be written as a linear combination of the other one this means that we got just a single linearly independent vectors and why is this important because we have seen in the definition of the basis that for us to have a basis we need to have a linearly independent vectors so the basis of vector space in this case a Comm space is a set of linearly independent vectors that need to spend the entire Vector space in this case R2 so therefore we need to look into the ca that we got in here and select one of these two vectors that can be considered as linearly independent let’s say we pick one three now we know that we can then write any Vector in R2 as a linear combination of of this Vector 13 so we can scale this Vector 13 and get a new Vector in R2 therefore we are saying that the basis of Comm space basis of Comm space space of a is then the set of one three because one three so A1 is then linearly independent and the span of A1 is R2 now when it comes to the uh bases of the entire R2 one thing that we can notice is that this A1 so one three it’s not forming it’s not spanning the entire R2 because because we cannot uh write any random Vector in R2 as a linear combination of these two therefore we are saying that this is the basis of Comm space but we are not saying that this is the basis of R2 and the final element in this definition that I want you to uh focus on is that every Vector in the space can be expressed as a unique linear combination of the bases vectors so in here we have looked into this idea of basis of a new space and the base of Comm space and we saw that we are talking about specifically the new space and Comm space but when it comes to the entire space for instance the basis for R2 then the basis of Comm space for instance is no longer um helping us because the basis of com space it consists of this Vector one tree and this one tree alone is not satisfying the second criteria that says that this Vector needs to spend the entire Vector space because this one tree Vector it’s a single vector and this Vector it is not forming the entire R2 it’s not um the basis for R2 it’s not spinning the entire uh R2 so given that D1 Tre is not spinning the entire R2 because of that we know that the one tree is not the set of one Tre is not the basis of R2 so this distinguishing of the basis of R2 based basis of Comm space basis of no space is really important because basis for R2 it means that we need to find set of linearly independent vectors that they together form the entire R2 they spend the R2 which means any random Vector that we can see in R2 we can represent as a linear combination of the vectors in this space so in here let me also prove that this one tree alone is actually not forming the R2 it’s not spinning the R2 which then uh concludes that they are not the it is not the bases of R2 and after this I will then provide you an example where we have a set of vectors that span R2 and are linearly independent which means that they are the bases of the entire R2 so first I want to show you why this single Vector one Tre is not the bases of R2 so being the base of R2 we have the criteria that the vectors need to be linearly independent so let me actually clear up some space here so I want to see and find the basis of R2 first I want to prove that this set which is the basis of Comm space I want to prove that this is not the basis of R2 then I will also as part of the second part of this proof look in look into the case when we do have vectors and the set of vectors it forms the base of R2 so the first thing the first criteria of the basis of R2 says that let’s qu it 1.1 the first criteria says that this Vector in this Vector space it need to be they need to be linearly independent well that criteria is valid given that 13 is linearly independent this means that criteria one is satisfied so whenever you got just one vector this criteria is automatically satisfied so then you have the 1.2 which says that we need to have this span of these vectors equal to R2 so is the span of 13 the R2 well no and how we can prove that because the idea is that any Vector including an example where I have for instance uh let’s say four and five this Vector that I need to be able to find find a scaler that will help me to create a linear combination let’s say C linear combination using this Vector 13 which will then set this amount this to be equal to this which means that I need to be able to write my random Vector 45 as a linear combination of this Vector that forms my uh Vector space so let’s see whether that is even possible well here I got four and five if I do this multiplication in the right hand side I get C and here I got 3 C because C * 1 is C and 3 * C is C and this means that I have an equation 4 is equal 2 C and 5 is equal to 3 * C from this I get that the C is equal to 4 and C is equal to 5 / to 3 but that is impossible because 4 is not equal to 5 / to three which means that I’m proving in here and I got to prove that the uh any random chosen Vector 4 five cannot be written as a linear combination of this Vector that forms this uh space therefore as random Vector from R2 can’t be written as linear combination of one Tre criteria two is not satisfied because for that we had to say that this pen of one3 is equal to R2 which we saw that it’s not the case because then we would have been able to represent this four five as linear combination of this one Tre Vector okay so now we have proven that the one Tre is not forming the basis of R2 let’s now look into what then does form the basis of R2 an example of it so we are familiar with the unit vectors E1 and E2 into r 2 which form the identity Matrix and this is 1 Z and this is 01 also 1 0 0 1 in the form of a matrix so in this example we have a set consisting of E1 and E2 where this is this E1 this is the E2 and the set corresponding to this Vector space is then 1 Z and then 0 1 and now I will be proving that this space this Vector space does indeed equal to the bases of R2 so this is the basis of R2 so the first criteria of the basis is that these two vectors should be linearly independent now we can quickly uh remember from our previous theory that the two unit vectors one0 0 1 are actually linearly independent that’s something that we have proven and you can easily see it also from here there is no way that you can find um scalar C that you can multiply this Vector with and get a vector zero one because for that for this one to become a zero you need to multiply this with 0o but then 0 * 0 is not equal to 1 which means that there is no way that you can find a scalar C to multiply this E1 to get the E2 so let me write this down E1 and E2 are linearly independent because there is no scalers C which is a real number such that such that c * E1 is equal to E2 so this means you can’t write E2 as linear combination of E1 or vice versa this means that E1 and E2 are linearly independent and this satisfies our first criteria so criteria one is satisfied what we have also learned is that any Vector in R2 can be actually written as a linear combination of a unit vectors that form that um R2 in this case 1 0 and 01 so let’s assume that this random Vector is C1 C2 so this is C vector and what we want to prove is that we can always write this C in terms of a linear combination of these two vectors and how can we do that well let’s say here we got a K1 K1 which is a real number and we multiply this by 1 Z and then we add K2 K2 and then here is 01 so this is our E1 this is our E2 can we do this well what is this this is equal to K1 0 Plus 0 K2 and what does this give us well this means this amount let me write it over K1 * 1 which is the E1 plus K2 * 01 which are which is our second Vector E2 this is equal to K1 0 + 0 K2 and this is equal to K1 K2 so I got on one hand this Vector C1 C2 which I want to write as a linear combination of K1 E1 plus K2 E2 if I take the K1 equal to C1 and K2 K2 equal 2 C2 well then in that case I can prove so this is basically equal to C1 and C2 which means if I take this K1 and K2 equal to C1 and C2 respectively and those numbers are given then I can represent this Vector c as a linear combination of E1 and E2 which is what I had to prove in order to say that the span of 1 0 which is the E1 and 01 which is the E2 is equal to R2 because any random Vector that will be provided to me with an element C1 and C2 and those are just real numbers can be written as a linear combination of these two vectors this means that the spend of these two vectors is equal to R2 and this is basically the second criteria so criteria two satisfied and if the criteria one and criteria 2 are both satisfied it means that this Vector space of 1 Z and 01 this is the basis of the entire R2 so let’s now talk about the concept of projections by definition a projection of a vector a on two not Vector B is the orthogonal projection of a along B it’s denoted by approach and then B underneath here we see the index and then a so projection of a onto B so here is the A and here is the B and represents the component of a in the direction of B so component of a in the direction of B all right so in order to properly understand this concept the intuition of it let’s actually make use of the R2 space so let’s first start by picturing in our flat world the R2 coordinates so the Cartesian coordinate system so let’s say here we got our y AIS here we got our xais is so this is the X this is the Y and uh here we of course we need to keep in mind this is just an example when it comes to projections we can always go beyond R2 but for keep it simple and truly understand this Concepts and this intuition behind the projection I want to simplify this and do the example in r two so here uh imagine that we got this line and this is our line that goes through the center that’s called this line B so B is line in R2 let’s say this is that line and now that imagine that we have this Vector which is part of this line let’s say this is this line and this line is the representing by uh on this line we got this Vector B and this Vector is basically part of that line as you can see this is the vector B on this line B so we know from this concept of the line spanning the R2 and then vectors we know that in this case independent what is the magnitude of this Vector what is the direction of this Vector we can represent this line B by this linear combination based on this Vector so linear combination of this Vector which is in this case D set set then here we got some C where C is a real number multiplied by this Vector B knowing that this C is just a real number so let’s make it actually green so we can basically say that this entire line B can be represented as the set of this linear combinations of these vectors so for instance if this is one and we do the C isal to two then we can get this part of so we can get this Vector otherwise if C is equal to three we can get this vector or C is equal to 4 this vector and then and so on which means that we can always come up with a linear combination forming a part of this line therefore we are seeing that this line can be represented as all these linear combinations uh of this Vector B which is part of this line and here this C is just a scalar so a number which is a real number so this C * Vector B represents this uh entire line so we will knit this in a bit but for now imagine this line and part of this line which is this Vector B so imagine then that we got yet another Vector which is let’s say in here I again going from the center but this time in this different direction so in here this is Vector a we call this Vector an A so you can see that this Vector a is actually much longer than the vector B and we see that V Vector a is not lying on the same line as B so B is lying on the line b and a is not lying on the line B now let’s say we want to project this Vector a onto this Vector B which means that we want to project this a in this direction so we want to bring this Vector a onto this line let me actually use a different color and the word of the projection actually does make sense in here as you might notice because we are trying to cast the shadow of a onto this line of B and how can we do that we can only do that if we connect this Vector a like this with this orthogonal line let’s say by using a different color of this so with this perpendicular line we then will be connecting the vector a to the line B because we want to project our Vector a onto this direction C so this perpendicular line that you see in here that goes from Vector a to the line B where on line B we have the vector B so here is the line a or line B and this perpendicular line it goes from a to line B and on line we we have the vector B that is represented like this then the projection of a onto Line B is this Shadow Vector that you see in here and the word projection or the name projection actually does make sense because we are projecting this Vector a onto this line and it creates this Shadow so we are casting this Shadow on here and and this Vector is what we are referring as projection of vector a onto Line B notice that we don’t say projection of B on Vector B but instead we are saying projection of a on the line B then another thing we can notice is that we are getting this projection of a on B so this vector by taking the Vector a so Vector a and subtracting from that projection of a on B that is the formula for this Vector that we refer as a perpendicular that goes from a to line B so when drawing this perpendicular line from a to line B we are referring this as a minus projection of a b because you can see that this Vector is simply this Vector minus this Vector that is the um ex mathematical expression for this perpendicular line so how we can then find out what is this C that we got in here because we understand that that to get this exact formula for the projection of a on the line B we need to understand what is the scaler specifically what value are we using to multiply this Vector B to get to this point so what is that c what is c what is C such that c * B is then equal to projection of a on the line B because we can have different sorts of a linear combination of vector B on this line uh B and in fact B this line B is the set of all linear combinations of this Vector B and I want to know specifically what is the vector that we see in here what is the shadow Vector because this is the projection of a on the line B what we see in here now how can we do that well let’s first formally def find on this specific case what is the projection of a on this line B so projection of a on line B is some Vector that is also on line B where a minus projection of a on B is per pendicular or ortogonal two this is basically the definition of the projection of a on line B under this specific example so in this case the way we can find this projection is by looking into this C so this is what we are interested this specific specific c times B vector and knowing C and knowing B we already know what is B what B is knowing C we can then describe this specific projection so one thing that we can know is the condition under which we say two vectors are a topen not that’s something that we already have learned as part of the previous lessons so let’s go ahead and find that amount so now what we need to do is to calculate this value of C because value of C calculation will then lead us to the exact uh Vector that we are interested in which is this projection so our end goal is to find out what is this projection of a on B this is what we want and for that we need to calculate this C because we already know the vector B so let me quickly remove this part cuz here we will then do our calculation so one thing that we need to make use of is this part when it says orthogonal because we know that if two vectors are orthogonal then their dotproduct is equal to zero so we know that this Vector is orthogonal to this target Vector which means that we can say that the Vector a and then minus projection of a on B multiplied with Vector B that this is equal to zero this is something that we know by definition of orthogonality two vectors are orthogonal it means that their dot product is then equal to zero now let’s make use of that part so this means that we need to describe this projection of A and B we need to make use of the fact that we know that this projection of a onto B is actually some linear combination of vector B so let me actually go ahead and remove this part we already know the definition so let us go ahead and calculate that c that we need in order to find out what is this entire projection so few things that we need to clear out is those formulas because then we can make use of them to find the C so we know that by definition the projection of a on the line B it is this vector that we get where we draw this perpendicular line from Vector a onto Line B and we said that this line is equal to this amount this is simply the vector a minus this Vector the shadow Vector which we said it’s defined by projection of A and B this thing so we can make use of that because we also see in here that this we are saying isogonal to this vector so given that this uh Vector a minus projection a b is orthogonal to line B that is also orthogonal on this specific Vector which is the projection itself so from this we can make use of the fact that two vectors when they are orthogonal their dotproduct is equal to zero in order to find this uh value of C so firstly we just said that D A minus projection of a on the line B that this multiplied by this Vector B is equal to zero because those two lines they should be perpendicular but at the same time we know that this is simply the linear combination of this vector because this line is perpendicular to this one and this line is some linear combination of this Vector B because if I have here a vector and then I have the longer version of that Vector on the same line which is then a linear combination of this original Vector let’s say this is my Vector B then this second Vector that I in here is then equal to sum C * Vector B this is also exactly what we said in here we said any Vector on line B can be represented as a linear combination of vector B and this is exactly what we are seeing in here so this projection is simply that c times Vector B this is something that we have already said so we are just making use of that to fill in that volum so this then results in a minus this C * B multiplied by this Vector B is equal to zero formula so here we are simply making use of the fact that the projection of a on to B is the shadow Vector which is then equal to some linear combination of this original Vector B which is on this line B then I can easily find the scalar C from here because we know how we can easily calculate this dot product so let us actually go ahead and do that let’s first multiply this a by B and then minus so I’m simply opening the parentheses C * then I got B by B and this equal to zero so C * B * B is then equal to a n B which means that c is equal to a * B / to B * B now when we have the C we can easily derive the formula for the projection of a on the line line B so this is the first part this is the second part so then the projection of a on B so projection of a on B is equal to this C c times the B and we just found out that this is equal to the C was equal to a * B / to B * B and now we need to take this C and then multiply by Vector B this is then the projection of a on B this Vector so projection of a on line B so you will notice that this is the same that we just got so whether you compute the projection of a on the entire line b or projection of a on the specific Vector b as we are using the vector b as a source for drawing our line this is the same as the projection of vector a on Vector B and this is the same formula as we seen here so this is the projection formula that we have just uh found out so projection of a on to B is given by this formula a * B so the dotproduct of the vector A and B divided to the dotproduct of the bay with itself and multiply it with the vector B and this is the in here this is something that we have calculated time and time again in our examples so if we go back to our example then here we can see that this is our Vector B this is our Vector a and we are saying if we take the vector a and we project it onto this Vector B then we can calculate this projection which is in here the formula for this entire Vector which we are calling projection of a on b or projection of a on B this can be find out so the the length of that Vector we can find by by using this formula so the dotproduct of vector A and B divided to the dotproduct of B with itself and then multiplied with Vector B so again a DOT product and this is of course something that we get as a vector so this is a vector something that is equal to this entire Vector in here this Vector so uh I know that this uh might look bit messy because it contains many moving Parts but I wanted to provide this detailed explanation and this step by-step process even if it is bit confusing and bit uh messy um in the beginning because this help us to understand what this uh formula is about and what is the intuition behind it because what we are doing is that we are making use of the fact that the line can be represented as a linear combination of all the um vectors that we use in here so this is Vector B and this entire line B is a linear combination of this Vector B and we can make use of that in order to find that scalar that we are multiplying to create this single linear combination that will end up giving us this Vector that we see in here which is the projection the projection that we are interested which is this line This is the projection that we are defining by this projection a on to B and we can get that by making use of the fact that this this perpendicular line that we are creating in here which is simply the vector a minus this projection this is this Vector this projection Vector that this is perpendicular to this line B and if the vector B is part of this line B this means also that this line a minus projection a is also perpendicular to that vector vector B making use of that formula we can then uh make use of the product of the two we know that the dot product of two perpendicular vectors is equal to zero making use of that we can then obtain this specific scaler C that we need in order to get the final formula for our projection we are interested in this C because knowing C we can and then multiply with this Vector B to get our final projection and we have found that that projection a on B is defined as the dotproduct of the A and B divided to the dotproduct of the B with the B and multiply with the vector p and this is again a vector now let’s look into a couple of numeric examples to clarify this topic and practice with it so given vectors A and vectors B find the pro ejection of a onto B so without looking into answer I will quickly go onto that example so Vector a is this Vector 3 4 can also represent this by our more common notation which is three and four and then Vector B is one and zero so let’s quickly draw our coordinate system this our x-axis this our y AIS and then what is the a the a is three and four three and four so this is our a and what is the B the B is 1 and zero which means that our line B is then C * the vector B given that the C is a real number and one thing that you can notice is that the line B is actually our x-axis it is this line this is our line B this is our line B so the projection is then this line this is our projection because we can know that by drawing a perpendicular line in here from a to the line B we can get then the connection between our Vector a and Vector B and create our projection so this is then the a minus projection of a on line B and this part is then this is then this projection a on B and how we can get this projection well we just learned that the projection of a on B is equal to dotproduct of a with B divided to dotproduct of B with be B itself and multipli it by B this is the formula that we can use and even if you don’t remember the formula by heart you can make use of this visualization to figure out what that formula is because we know that if this line is perpendicular to this one then a minus projection of a on B multiplied by this projection a on B should be equal to zero and this projection of a on B is equal to some scalar C multiplied by Vector B that’s something that we see in here the first thing we need to do is to compute the dot product between a and b a * B is equal to 34 multiplied by 1 Z this is the dot product which is then equal to 3 * 1 + 0 * 4 and this is equal to 3 the next thing we need to do is to compute the dotproduct between B itself so B * B and what’s that that is 1 0 with 1 0 multiplied this is equal to 1 1 * 1 + 0 0 * 0 is equal to 1 then the Third third thing that we can do then is to obtain the final value which is projection of a on B is then equal to 3 ided 2 1 multiplied by Vector B which is 1 0 which is equal to 3 0 and this actually makes sense visually too as you can see in here this is the tree for the x-axis and here we have the center zero so this projection is then the vector 3 0 so even without calculation we could see just from plotting the uh on the coordinate system the vectors A and B that the projection of a on B will be this Vector 3 Z but we have followed the formula in order to do calculation step by step which is something that you can see in this answer to so the projection of this Vector a onto B is then this Vector of a length tree in the direction of B so you can see that it is of the length of three so this is the tree on the direction of B so on the line B let’s now move ahead and look into a different example but this time we will do the calculation in a quicker way so we got two vectors 43 and B is equal to 2 and we need to find this projection of a on to B so the first thing we need to do is to calculate the a * B which is equal to 43 * 2 0 and that’s equal to 4 * 2 + 3 * 0 and it’s equal to 8 the second thing we need to calculate is the B do product with B which is equal to 2 0 2 0 this is then equal to 4 and the final part is to take and uh from this one and two this values and then bring them all together so then the projection of a on B is equal to 8 / 2 4 multiplied by the vector to0 and this is equal to 8 / to 4 is 2 2 * 2 is 2 2 * 0 is 0 so we are getting this 2 Vector so projection of a on B is then this Vector 2 which is actually on this x axis similar to what we had before only with the length of two on uh towards the direction of B which is then equal to 4 and z and this is again similar to what we had before uh where we got the projection of a on B on that end up on the xaxis but now with a length of four so now our projection has as the following Vector so the uh following magnitude and Direction so this is the step by-step process that I just followed if you want to do it bit slowly and this is the final result so uh the interpretation of this projection is that this projection a onto B is simply this 4 zero this means that the A’s component in the direction of B is spends uh four units along this x-axis that we saw in here because this is the value X this is the value of y so this projection shows us that a influence in the direction of B is completely horizontal with this magnitude of four because we saw that we end up with the projection on the x-axis again so this was four this was our projection vector and if you plot this entire Vector a and Vector B on this xaxis and Y AIS then you can clearly see that the uh horizontal line that we end up with the uh projection of A and B is very similar to what we had before in here let’s now talk about a concept of auton normal bases so let’s now Define what the auton normal bases are so by definition auton normal basis for a vector space is a basis where all vectors are orthogonal or perpendicular to each other and each Vector is of unit length so as you can notice here here we have a special type of basis it’s called auton normal basis because in the beginning of this section of this module we defined formally this concept of bases we talked about the concept of calm uh space and then the uh basis of a Comm space the no space the basis of a no space and then we talked about the concept of the basis of the entire space for instance dr2 and now we are defining a special type of bases which we are referring as auton normal bases and this auton normal basis as you can see from this definition it contains two criteria for it to be uton so an uton basis for Vector space is a basis where a all vectors are orthogonal or perpendicular to each other and B each Vector is of unit length we already have learned that when we have vectors let’s say Vector A and B perpendicular it means that A and B their dot product is equal to zero that’s the first CRI IA that we need for calling our basis an auton normal basis then the second criteria is that each of these vectors they need to have a length of one if we have this condition satisfied then we are saying that our vectors they help us to form this autona basis if we got three vectors forming this Vector space it means that we need to have the a * B = to0 A * C = 0 and then B * C = to zero this is if we are in in case we are using three different vectors that Define our Vector space in this case we make make this part smaller so let’s put the length of B in here in this case the second criteria becomes that the length of a is equal to the length of B and then is equal to the length of c and is equal to one so depending on the number of vectors that you use to form your vector space the prove that you are dealing with auton normal bases will be different here we got just two vectors here we got three vectors but in both case we first need to prove that we are dealing with uh vectors Each of which are a set of orthogonal perpendicular vectors and all of them pairwise they need to be perpendicular and at the same time the second criteria says that they all need to have a unit length so their length should be equal to one we need this auton normal basis in order to simplify our calculations including the calculations of projections and Transformations that we just saw before when we were discussing this concept of projecting a vector onto a line or projecting a vector onto OD Vector because we were in this basic case when we had just two vectors in R2 and calculating projection in R2 is very easy because we can make use of this formula um a a and then B uh the dot product of them and then divided two dot product of the B and then times the B this was quite straightforwards right but when it came so this is the projection of a on B but when it comes to projection in higher dimensional space let’s say you have R5 or you have r00 or R th000 then it becomes much more difficult to do those projections and to calculate data projections and for those cases we can make use of this concept of auton normal basis to simplify our calculations and we will see that in a bit so let’s first understand this orthogonality and the normalization part so orthogonality refers then to the part of uh when we are saying that the vectors should be orthogonal to each other and the normalization refers to the fact to the fact that the length should be one this is basically the set of two criteria area that I just discussed this is uh the summary slide that will give you an indication what is meant by that so if we have two vectors V and W then we say that the first criteria is that those two vectors are orthogonal which means they’re dot product is equal to zero and we are saying that their length is equal to one which we are referring as a normalized vector so if the vector has a length of one then we are calling a vector v normalized so if both of this criteria of normalization and orthogonality is satisfied that we are saying that we are dealing with an uton normal basis so now when we have learned this idea of projections also this idea of autog colonization and the uh concept of auton normal bases we are ready to discuss the concept of the grme process so the gram shade process is this method for orthogonalizing a set of vectors in an inner product space and turning them into an auton normal set so let’s say we have a set of vectors we want to uh bring and transform all these vectors onto this auton normal set of vectors which means that we want them to be aut toonize so we want them to be perpendicular and we want them to be normalized because we know that the two criteria were specified right so the first criteria was that we need to have vectors ortogonal hence we are doing orthogonalization and the second criteria was that they need to be normalized because we want the vectors to have length one so we are doing normalization this process of turning this set of vectors onto this auton normal set by using this method of orthogonalization which is something that we are referring as a gamish made process this is something that we can use in order to simplify later the different sorts of Transformations which we need in order to perform bit more advanced uh Transformations like Matrix uh factorization different decomposition techniques so given the set of linearly independent vectors this process which we are referring as grme process produces this auton normal set that is spinning the same Subspace so we have the same Subspace it’s just that we are turning the set of vectors into an auton normal set of vectors that is spanning the same Subspace so the grum Street process step by step looks like something like this so given the vectors A1 A2 up to a n the first thing we need to do is to start with the vector V1 which is equal to our first Vector A1 and first we need to normalize this vector and how we can normal normalize this Vector well we need to take this vector and we need to divide it to its length so the grme process step by step will look like something like this so in the first step what we need to do when starting with these vectors of A1 A2 up till a n so in RN we need to First Take the first vector and we need to normalize it and how we can normalize the vector and ensure that its length is equal to this length of V1 well we need take that vector and we need to divide it to this L because when we take the vector V1 and we divide it to its length of V1 then we will ensure that the length of that Vector is equal to 1 we can actually prove that very easily but I won’t do it in here uh feel free to go through the process assuming that the length of the vector what what you want to achieve at the end is that the length of vector v is equal to one this is something that we want to achieve and this normalization process can be done if we find a way to ensure that we uh get this E1 because E1 means that we end up with this Vector y 000000 0 this will be for first Vector so V1 this is E1 so the one is really important here so we want to normalize this Vector V1 by uh ensuring that we get the E1 so we go from V1 to E1 and the way we do that is that we take the V1 and we divide it to the length of V1 and in this way we get the E1 so the normalized version of P1 1 is E1 so then for each subsequent Vector a which means A2 A3 A4 up to a n we need to subtract its projection on all the previously computed orthogonal vectors in this way by using this step two we are ensuring that all is different each pair wise set of A1 A2 and then A2 A3 Etc they are all orthogonal to each other and we know that this projection is something that we got when we had this two perpendicular lines so we had this Vector we’re projecting onto this Vector we got that by finding this perpendicular line and making use of that using this property we are then making use of that in order to see how we can ensure that the subsequent Vector that we have is always perpendicular to this one so let me actually write down what is in this formula so here VK is equal to AK minus the sum of all the projections so then we need to normalize the VK to get the EK and then we need to repeat this Step 2 and three for over vectors which means that first here we apply this normalization on the vector A1 so V1 is equal to A1 and then we get the normalization by getting this E1 so E1 is normalized version and then we need to apply a bit different tactique for our V2 V3 up to VN and then let me actually write down this for this General case so what this processed this the gr let me ensure that I’m not making a typo processed step by step means step number one for vectors A1 A2 A3 dot dot dot a n so we are in the RN then step number one basically says take the V1 and set it equal to this first element V1 this is A1 then what we need to do is to normalize it to get the E1 so normalize normalize V1 to get E1 which is equal to 1 0 0 0 and then dot dot dot zero and the size of is n by 1 and how we can do that by taking this Vector V1 and divided it to the length of V1 which basically means in this specific case A1 ided to the length of A1 this will then give us our A1 this Vector this is basically what the step one entails then in the step number two we have for each subsequent AK where K is just an index referring to whether we are dealing with K is equal to 2 so uh A2 A3 and then dot dot dot a n this is what basically the K is used for to refer to which Vector we are dealing with we need to subtract is projection on all previously computed orthogonal vectors by using this formula so let’s actually do a couple of those case to see what is going on for instance for K is equal to 2 so K is equal to 2 and here is the formula by the way so VK a VK is equal to a k minus sum K is equal to K starts with one and then then me use a different index so I is = to 1 till K minus one and then projection of AK a K on E1 or EI I so the eii that we have just computed because every time you are then normalizing and normalizing every time your vectors and then you are uh finding out what is the projection of your vector a onto that EI and then you are subtracting that from your vector so what this means in Practical terms when for instance your K is equal to 2 it means that V2 is equal to a 2 minus sum of I is = to 1 and then K is = to 2 K minus 1 this means this is 1 projection of a and then 2 on A1 given that this is one this is simply equal to A2 minus projection of E1 that’s normalized version of E1 and then A2 so projection of A2 on E1 and then in the step number three we need to do we need to go from VK to get EK so basically we are ensuring with the step number two the orthogonally orthogonality condition and with step number three I me add some spe Cas in here so in the step number three step number three we then saying let’s normalize normalized this VK that we have just computed in here because we remember that the second criteria after tonality is normalization that the unit or the length of the vector should be equal to one so then V K in this case for K is equal to 2 for K is equal to 2 means that we need to go from V2 to E2 and the way we can do that is by taking the V2 by V2 and then divide it to the length of V2 this will then give us the E2 this is the normalization part and this step number four basically means repeat repeat step to entry for all case which means that if we go back so we are done with V2 so we have obtained V2 and then we have obtained normaliz normalized version of V2 by getting this E2 we are ready to come back and do the same for K is equal to 3 and for K is equal to 3 in Step number two we got V3 is equal to A3 minus making use of this formula sum overall I is = to 1 K – 1 is = 2 and then projection of this time A3 see three k is equal to three and then on A2 actually it says EI let me remove this this otherwise we would have made a mistake this should be I because then I will change per K this is the entire idea we need to re um subtract all the um projections what this basically means is that we need to take A3 and this time given that here we have two instead of one in here we need to have an extra step which means A3 minus and then what this formula basically says this is the sum of the projections of A3 on e i where I goes from one to two so projection of a Tre on a one when K so when I this is the I is equal to one case plus projection of a Tre on A2 this is the I equal to 2 case this is basically what this summation says this is this element and we have seen this as part of the high school but also the pre-algebra course okay so now when we are clear on how we can calculate the V3 in the step number two for K is equal to 3 we are ready to go onto the step number three and what was step number three the step number three for K is equal to Tre was saying let’s take the V Tre and nor normalize it to go from V Tre to e Tre and how we can do that by taking the V Tre and dividing it to the length of V tree to get on to E Tre and this cycle goes on and on until we cover all the case so all the vectors so the idea is that we first for our initial tab we set the V1 equal to A1 we normalize it then starting from the K is equal to 2 we don’t go first on and on WE autal it by formula in here by using this we can ensure that each of these vectors is then orthogonal to all the other vectors so for K is equal to 2 we ensure that this uh vector that we get is orthogonal to all the other ones and the cas is equal to treat that the third Vector is orthogonal to all the other ones and we are doing that in Step number two so for each case for each K we basically are ensuring that in this case we have an a vector that is autal to all the other vectors in this set and for each Vector we are also normalizing it to satisfy the second criteria because we had this two criterias to create this auton normal set so we are doing this in subsequent uh way so first for K is equal to 1 so basically for A1 and then we are doing this for K is equal to 2 so A2 and then until K is equal to n so a n what we are doing every time is that we are obtaining this V1 and then we go from V1 to E1 to normalize it and then here we are getting the V2 here to go to E2 by normalizing it so this basically the step two and step three and then we do this every time and up until to the point of obtaining VN and then from VN we go to to normalize it so this is the idea of this entire process step by step step to start with V1 as part of the step number one and then as part of Step number two for each subsequent Vector a k so K is equal to 2 obtain the VK and then normalize it for K is equal to 3 obtain the V3 and then normalize it to get E3 up to the point of the last Vector which is a n the vector a n we compute the VN and then we normalize it to get the and this is what this part is which is the step number two that says repeat steps to entry for all vectors it means that every time when you increase your K when you go into the next Vector we first compute the V so VK and then you normalize it you get the e k and then you go back to the step number two or three because you then again need to calculate the VK and then EK and then for the next case so this is something that you will see also a lot when you are writing Thea code for your uh algorithms because in many cases you need to do this repetion of the steps so uh you for one vector you do something or for one iteration you do process and then you uh go back and do for the next one and for next one this process is what we are referring by repeat step number two and three for all vectors so let’s now look into an example let’s apply this grumme process two vectors A1 and A2 where A1 is 1 1 0 and A2 is 1 1 so let’s go ahead and do that so A1 is equal to 1 1 0 A2 is equal to 1 0 1 we want to apply this grum process to create this auton normal basis for the Subspace that is pented by A1 and A2 so now we have the set 1 1 0 and one 1 and what we want is to create an autonoma basis so creating creating or to normal normal bases with from M process so here we got only two vectors so obviously it’s this and it’s a very simplified version of it what was the first step in our case uh in our algorithm it was to set the V 1 = to A1 what we need to do step number one we need to set the V1 equal to A1 and we need to normalize normalize the V1 to get E1 that’s what our goal is so let’s go ahead and do that V1 is equal to A1 and is equal to 1 1 0 that’s our A1 so 1 1 Z and in order to normalize V1 and get the E1 we know that this is equal to V1 / to the length of B1 which is then equal to take this V1 so that is 1 1 0 and then divide it to the length of V1 and you can very quickly see that given V1 is equal to V1 * V1 that’s something that we learn in the very beginning of our fundamental to linear algebra course that the length of V1 is simply the dotproduct between uh V1 and V1 and it’s equal to 1 1 0 * 1 1 0 which is equal to 1 + 1 so 2 so this is then equal to 1 1 0 / 2 which is equal to 1 / 2 1 / to two and then is zero this is our E1 so we are done with our step number one because now we have B1 and we got E1 so what was the step number two in the step number two we need to set the k equal to two this is the next K so for A2 what we need to do is we want to get V2 and normalized V2 by getting E2 and how can we get that well first let’s find what is the V2 well V2 was and using that formula that we saw before which was this formula so it’s equal to AK minus and the sum I is equal to 1 to K minus one and then projection of a onto EI I so let’s take this formula over this is equal to a 2 because K is = to 2 a k minus sum and then I is equal to one till K minus 1 and then Kus 1 which is equal to basically 1 given that K is equal to 2 and then projection of A2 onto e i Y and this is equal to H2 minus given that we got K minus y is equal to 1 so the limit for our summation is equal to 1 so this one this means that like before we got just one part as part of our summation so minus and then projection of let me actually keep the same color I want it to be consistent so projection of A2 on the E 1 so you see here the i i is equal to 1 and the limit of the I is K minus one which is equal to 1 so we got here just E1 so we got the V2 formula we can then now calculate because we know A2 and the A2 is this so one0 one 1 0 1 but now we got a problem we don’t know what this is so let’s quickly go and calculate this part so projection of A2 on A1 and we learned from the projection formula that this is equal to A2 * E1 / 2 E1 * E1 so the dot product multip by E1 and what is this this is equal to 1 1 multiplied by and what is the E1 E1 we just calculate in here so it is 1 / to 2 1 / to 2 and then zero here / 2 and then 1 / 2 1 / 2 and then zero multiplied by 1 / 2 1 / to 2 and then zero here multiplied by the same Vector so E1 so this two cancel out this two also cancel out and as you can see we are getting that the projection of A2 on E1 is equal to this Vector we can also manually check that actually so let’s let’s do that so let’s see we are not canceling out these vectors and instead we are manually calculating this so here we got 101 ultip by 0.5 and 0.50 this is equal to 1 * 1 / 2 is 1 / 2 0 * 1 / 2 is 0 1 * 0 is 1 so + 1 IDE 2 this amount is 1/4 + 1/4 this multiplied by the V Vector 1 / 2 1 / 2 and then zero in here this is equal to 1 / 2 1 + 1 / 2 is = to 3 / to 2 and then 1 1/4 + 1/4 is equal to 1 / to 2 multip by 1 2 and then one 2 and then zero what is this amount well those two can cancel out so we end up with three times and then 1 / 2 2 and then 1 / 2 and then zero this is then the projection 3 / 2 3 divided to two and then zero so let me remove all these calculations and then we can take over the projection value which is 3 / to 2 3 / to 2 and then zero to get our Vector V2 which is equal to 1 – 3 / to 2 0 – 3 / to 2 and then 1 – 0 and this is equal to here it is 1 here it is – 3 / 2 and here is minus and then 1 ided to 2 because 3 / 2 is minus uh it is 1.5 and then 1 – 1.5 is simply – 0.5 so this is then the vector V2 then what we need to do is to normalize this Vector to get D E2 which is then equal to V2 / to V2 length which is simply equal to V2 / to V2 * V2 so the dot product and this is equal to let’s take the V2 which is -1 / 2 and then Min – 3 / 2 and then 1 and then divide it to and this amount let’s quickly calculate that it is equal to so the length of V2 is equal to – 1 / 2^ 2 + – 3 / 2^ 2 + 1 this is equal to 1/4 + 9 / to 4 + 1 which is 4 / to 4 and then this is equal to 1 + 9 is 10 10 + 4 is 14 so 14 / to 4 this is the length of it so 14 / to 4 so then this is equal to this Vector to this threedimensional vector -1 * 14 -1 / 2 * 14 / 4 is equal to this is 7 so minus 7 / 2 4 and then – 3 / 2 think I just made a mistake here actually so minus 1 / to 2 so the first element and then divided to 14 / 4 is actually actually equal to this multiplied by 4 / to 14 so you take this element then divide it to this one and we know that a / to B * C / 2 D is equal to a * D and then B * C so we are basically flipping this side this is from pre-algebra and then here this is equal to 2 and then is = to – 1 / 2 7 then let’s sh the second one too so we got – 3 / to 2 / to 14 / to 4 is actually = to – 3 / 2 * 4 / to 14 and then if we remove this this is then two this is seven this cancel out this equal to -3 / to 7 – 3 / to 7 and then finally we got 1 / 2 14 / to 4 which is equal to 4 / to 14 this equal to 2 / to 7 so 2 / to 7 and this is our A2 and given that we got just two vectors so we have already reached the end of our solution so now when we have already the V1 and the V2 the E1 and the E2 We have basically completed the process of this grummet uh procedure because we have already uh only two vectors that means that we need to have V1 and V2 and then uh E1 and E2 and this is all that you need in case you got two vectors if you have three vectors of course the process will include um the same process of Step number two and three so the V2 and the normalization of it two times for your k equal to 2 and k equal to 3 and then if you have more vectors then every time you will have more of the steps but at the end what we want to have is the set of vectors that are orthogonal and at the same time they are normalized in this case we say that this vectors form this orthonormal bases now why is this important the applications of orthonormal bases well firstly it simplifies a complex Vector operations and uh this is the basis of many uh more difficult mathematical Concepts uh like for year series or quantum mechanics it’s used also um when it comes to this auton normal basis uh also signal processing and it’s a critical uh process in numerical methods especially in machine learning algorithms and in data compression so we will see this process to be Ed also as part of uh decomposition techniques which is really important when it comes to different algorithms uh whether it’s optimization algorithms but also um algorithms that are used for recommender systems for example and those uh Concepts they all come together and we will see later on when we will be discussing the concepts of the compositions and metrics factorization so this uton normal basis and this grum made process they are really foundational in linear algebra they provide tools for simplifying and also solving this high dimensional problems efficiently their application include different fields of science engineering demonstrating their versatility and utility let’s now talk about the special matrices and their properties so we are going to talk about special matrices like symmetric matrices and their example diagonal matrices and their corresponding example but also the orthogonal matrices with the corresponding example so when it comes to the special matrices special matrices have unique properties such as being symmetric or all nonzero elements on the diagonal like diagonal matrices or orthogonality uh in matrices which means that we have orthogonal matrices so when it comes to the symmetric Matrix it means that uh the a The Matrix a is equal to its transpose to a so a is equal to a in this case we can confirm and say that the Matrix a is symmetric so in this case we have Matrix a and we know that the way we need to transpose this Matrix is to taking this rows and making them The Columns of our transpose Matrix so a is then equal to 2 – 1 and then zero then the second row which is min -1 and then 2 and then Min -1 and then the third row which is 0 – 1 and two so the third row then becomes my third column so as you can see those two are the same so I’m using then the definition of the transpose of the um Matrix and then here then we end up with two matrices they are actually the same so we can see that the A and the a in both the First Column they got 2 minus one and a zero the second column Min -1 2 and minus one the third commn 0 – one and two so their columns and their rows they are the same which means that we are dealing with a symmetric Matrix so whenever we want to check whether the Matrix is symmetric we just need to take the transpose of it and see whether the Matrix is equal to its transpose in that case we are dealing with symmetric Matrix do also note that for a matrix to be symmetric it needs to be a square Matrix so it needs to be 2x two in the two dimensional space or 3×3 in the three dimensional space or n by N in N dimensional space which means that the number of rows should be equal to number of columns because otherwise when you flip your number of rows with number of columns on in case there is no um uh Square version of that Matrix so m is not equal to and in that case a will have a dimension of M by n and then a t so a t will have a dimension of n by m which means that there is no way that a can be equal to a this is not then possible therefore we need to have a square Matrix for them to be symmetric let’s now talk about diagonal matrix so a diagonal matrix has a nonzero element only on its diagonal which means that in this case we have this nonzero elements on the diagonal so let’s call it d11 d22 and then d33 this equal to 3 this equal to 5 this equal to 7 and all the elements as you can see in here they are zeros so the concept of diagonal matrices is very uh simple therefore we will then go through the next example which is about orthogonal Matrix now this is a concept that we haven’t yet seen and we spoken about so let’s code read through this bit slowly so an orthogonal Matrix is a square Matrix whose columns and rows are orthogonal unit V vectors so auton normal vectors and its transpose equals its inverse so there are two part of these elements so firstly it says that for the Matrix to be orthogonal Matrix it should be square Matrix so Square Matrix and then its columns and rows are orthogonal unit vectors so columns and rows are orthogonal unit vectors which means they need to be normalized so normalized so um we have seen when forming this uton normal bases that we had this process of uh this condition of orthogonality the vectors had to be orthogonal and they had to have a length of one which means that they had they had to be normalized we can see exactly the same in here so hence the name uton normal vectors so they are orthogonal and they are unit vectors which means they are normalized so then the final condition is added in here which actually is not so much a condition but rather than property something that we can prove that once we have all this we can also say that if we are dealing with orthogonal Matrix then Q T * Q so the dot product of the transpose with that Matrix Q is equal to the Q * QT is equal to i y because the QT is equal to the Q minus one because the transpose of that Matrix Q is actually equal to its inverse and given that we learned that the Q minus one so the inverse time Q is equal to Q inverse * Q is equal to I and given that here we are learning that QT is = to Q minus one we are then making use of this to claim this so instead of minus ones that we are used to when we are dealing with inverses here we have t the transpose so in this case this orthogonal Matrix that we have just learned about this is this Square Matrix who called rows are orthogonal and they are also normalized meaning that we are dealing with QT QT is = Q minus one it will look like this so this q1 you can see that here we got the first row here we got the second row and if we calculate the dot product between this row and this row we can quickly see that we are getting a value of zero so we can prove that that they are actually autog those two rows let’s go ahead and actually prove that so let’s call this R1 let’s call this R2 this is Row one and row two and I will leave the uh column version so q1 * Q2 that’s. product on you to prove that the columns are perpendicular I will work with the rows so R1 * R2 for me to prove that they are orthogonal I need to prove that this equal to zero can we do that well let’s try so 1 / 2 < of 2 1 / 2 < 2 multiplied by 1 / 2un 2 needs some bigger space in here so 1 / 2 of 2 and then- 1 / < of 2 that’s how I can calculate the dot product between R1 and R2 R2 and R1 you can see that the elements in here are the same and here the elements are also the same so then this is equal to 1 / 2 < of 2 * 1 2 of 2 – 1 / 2 2 * 1 / to of 2 I’m simply taking this minus and given that the dot product is basically plus and then this amount I’m just taking this and bringing up in here to a avoid one more step uh given the space is quite limited now what do we see in here this value is the same as this value which means that this is equal to zero and we know that the two vectors to be autal they need to have a dotproduct equal to zero so here we have proven that dotproduct of R1 and R2 is equal to zero so this proves that R1 and R2 so the two rows of this Matrix so R1 and R2 are autogo we can also prove that the second criteria of auton normal vectors is also satisfied in here we can prove that when we look at the length of this vector and of this one then they are of the unit one so let’s actually go ahead and and do for one of them so let’s prove that for 1 divided 2 Ro of two and then 1 / 2 Ro of 2 this is a vector that the length of it this is let’s say our first row so this is R1 then the R1 length is equal to 1 / 2 of 2 2ar + 1 / 2un of 2 2 this is equal to 1 / 2 + 1 / 2 and what is 1 / 2 + 1 / 2 it’s equal to 1 so we have proven that the length of R1 is equal to 1 you can quickly and E easily also compute that for the second row and you will then also prove that the R2 the length of it is also one which is then the second criteria which said that for the vectors to form this auton normal bases so to be auton normal vectors they uh also had to have a length of one so they had to be a unit vectors in this case then we can make use of the property that d q 2 transpose is equal to Q inverse and this then results in Q2 transpose time Q2 Q2 which is equal to Q2 * Q2 transpose which is equal to the identity Matrix and specifically I2 because we are in the R2 so both this Q2 and the previous example those are all to Al matrices and in here we have proven that the rows are indeed orthogonal and we have also seen that the length of them are unit vectors meaning that we have automatically got this I will leave this one to you to do those proofs so to uh ensure that the row one and row two are orthogonal so they are perpendicular which means they the product of their uh the dot prod of these two vectors is equal to zero and also that they are normalized which means the length of them is equal to one and this means that then this holds you can actually even go ahead and uh practice the material that we uh learned as part of the previous units by calculating the inverse of this Matrix and checking that the inverse of this Matrix is indeed equal to the transpose of the Matrix so that QT is equal to Q Q -1 because we learned how we can compute the inverse of a matrix because the inverse of a matrix was equal to 1 / the determinant of this Matrix times and then the manipulated version of it which was in this case 0 0 and then we need to have here one so Min – 1 * 1 and then 1 * -1 so we have to multiply this and this by minus so 1 one and then here minus one so in this way you can also prove that this inverse is actually equal to the Q2 transpose because then you can prove that indeed and you can see for yourself that this formula is in equal to the Q2 transpose because then you can prove that indeed and you can see for yourself that this formula is indeed true in this module we are going to talk about Matrix factorization we are going to discuss the significance of Matrix factorization we are going to Define Matrix factorization we are going also to discuss the common applications of Matrix factorization across different fields and then we are going to see detailed examples of Matrix factorization so let’s talk about why Matrix factorization matters so metrix factorization techniques they are essential for various reasons they are used for simplifying metrix operations like solving linear systems or when we have this um many uh matrixes but we want to um simplify these operations that we apply to these matrices and we want to solve the problem then we can make this uh complex Matrix operations more manageable and make this uh calculations more manageable by using metrix factorization techniques we can also use metrix factorization directly to solve system all linear equations efficiently we can also use Matrix factorization to perform igon value de composition singular value de their composition or called SVD and othero operations which are crucial in machine learning and data analysis so ion values and ion vectors you might have heard already they are part of also PCA which is the principle component analysis and this comes from uh fundamentals of statistics and the uh p a is used as a dimensionality technique and in fact it’s one of the most popular dimensionality techniques that you will find in the industry used in the data science used in data analytics machine learning even in the Deep learning so Matrix factorization can also be used to reduce the computational complexity by making use of this factorization we can then simplify the process and also make it more efficient for computation and it’s especially in important when we are dealing with this High dimensional data when we have many features or we have a very large model and complex model then this uh metric factorization technique can make a huge difference in our data processing process so these techniques underpin many algorithms in numeric analysis in optimizations and Beyond so whenever it comes to machine learning or data science or many other fields you will this uh process and this term Matrix authorization appearing a lot even um in the example of a streaming company Netflix which I’m sure that you are aware of Netflix is using uh metrix uh factorization to build a recommender system and uh metrix authorization usage in building recommender algorithm for personalized recommendations is actually one of the most popular applications of metrix factorization therefore I wanted to specifically discuss this to as part of our Advanced linear algebra course and some of the concepts might seem bit more complex than the ones that we have discuss as part of the previous units but once we go through them step by step and I will give you all the details in all these examples this entire process of these different metrix factorization techniques should become much more clear and straightforward so we will be discussing not just one but multiple fundamental metrix factorization techniques beside of talking the high level where they are used and how you can choose for what type of applications so we are going to demystify this entire concept of Matrix factorization and we are going to uh start from high level then we are going to go into the deepest details let’s now formally Define the metrix factorization so metrix factorization refers to decomposing a matrix into product of two or more matrices revealing its structure and simplifying further analysis so what is this idea behind metrix factorization the idea is that if we have a matrix a and we want to simplify our process of calculation or multiplication anything that’s related to this a but this a in itself it contains this weird numbers or it is just too complex you know it contains this ton of different numbers you don’t recognize where the columns are linearly independent it’s not very readable from the first View and you just want to make your life easier when performing this calculation well for that you can make use of this Matrix factorization to write this a in terms of some other matrices let’s say um and I’m calling here randomly Q or t so it’s equal to for instance the dotproduct of these two matrices Q * T where Q is much simpler and the t is also much simpler so those may contain vectors that are um for instance this can be a diagonal matrix or it can be a matrix uh with specific properties when using those you will feel much more comfortable so it will be easier for you to use them in order to multiply uh with other matri matrices it can be easier for you to solve this problem but of course if you are in the two dimensional space let’s say you are in R2 or in R3 then most likely it will be quite straightforward for you to use the a itself but if you are in the r 100 or r 1000 then of course this uh entire computations they become super complex it will be difficult to understand and compute this linear combinations find out whether you are dealing with a linearly independent columns find out um the um no space the column space the basis of the new space and cumn space and all this they might seem uh much more difficult when you are in high dimensional space for in those cases we can then make use of metrix factorization to make the entire process much more simplified and also more efficient this entire calculation process so common types of Matrix factorization include lower upper uh Matrix factorization or in short Lu QR factorization and INF famous type of factorization ation which is called orthogonal triangular factorization and then we have SVD singular value de composition yet another in famous metrix factorization and then finally the igon dec composition also another Super popular metrix factorization technique so uh the QR SVD and IA de composition are in fact highly popular the composition and Metric factorization techniques that you will see appearing in the 90% of all the statistics related and machine learning related books so this just comes to prove how important these concepts are when it comes to properly learning and mastering these more applied uh science related fields like machine learn so if you want to go beyond the level of knowing algorithms but rather than to also be able to edit the algorithms tweak them adjust them be able to understand machine learning algorithms deep learning algorithms data science at its core and in order to become a professional well-rounded professional then this I composition the singular valid composition and the QR metrix authorization techniques are techniques that you want to know and you want to understand at least higher level such that you can easier grasp more more advanced concepts that come from the applied sciences like machine learning and AI so let’s first discuss that high level what this QR decomposition is so what the QR DEC composition does is that it decomposes a matrix into an orthogonal Matrix which we are referring by q and then an upper triangular Matrix R so in here you can see that we have this two different matrices so we are basically saying a is equal to this product of this Matrix q and R where the first one this Matrix Q this one should be orthogonal Matrix so this part is really important and we have learned as part of the previous module the definition of orthogonal Matrix we learned that the rows or columns they had to be or Al to each other and we also learned that they need to have a length of one they need to um be normalized and we learned that this means that the transpose of those matrices is equal to the inverse of this matrices so this was just the last part of the previous module and this is exactly what this Matrix Q is about so we are saying that we will decompose I into these two matrices as a product of these two matrices q and R one of which this Matrix Q should be uh an nutal Matrix which means the rows and the columns they should be orthogonal to each other so their uh dot product each of them should be equal to zero and they need to be normalized so the length of them should be one for each of those rows and vectors and then the second part of this U the composition is this Matrix R which says that the Matrix R should be an upper triangular Matrix and what is the definition of upper triangular well in this case you can think of this r as this Matrix where we have here all zeros and then here on the diagonal you have numbers nonzero numbers and then here let’s say 1 2 3 4 five and then here in the upper part you will also have numbers so unlike in the lower part part of this Matrix R where you will have zeros in here you will have also n Zer numbers numbers let’s say 7even 10 uh 8 and I’m just writing these numbers randomly so of course in the real case when we have this Matrix a and we go through this process of QR de composition of course we will have an appropriate q and appropriate R where these numbers will be different and they will be specific numbers that will will will be calculating but the idea is that we need to get this upper triangular Matrix R for this calculation to make sense so we will then be using this qard composition for solving linear um linear Le squares problems for instance which is part of the linear regression too because linear regression from machine learning and from statistics uh it is based on the least Square technique the estimation technique that we are using for linear regression in machine learning um to solve this linear regression problem is called Ordinary Le squares so the algorithm is based on this idea of Le squares which is trying to minimize squared uh residuales of the model and that can be done by using this idea of QR the composition so it helps us to provide numerically stable solutions for this type of problems too and QR de composition is used extensively in Signal processing and statistical analysis let’s now briefly talk about the Lu decomposition so Lu DEC composition decomposes a matrix into lower triangular Matrix so this is the opposite of what we had before we can have an upper triangular triangular Matrix like we had in the QR the composition we can also have a lower triangular Matrix so you might have already guessed how it will look like I won’t go into that very soon in the QR composition example you will see the idea of the upper triangular I will also show the idea of a lower triang so the composition in case of Lu uh is done by decomposing a matrix into lower triangular Matrix l and an upper triangular Matrix U so basically the difference between the QR de composition and L de composition is that in the QR DEC composition we are decomposing a matrix into orthogonal Matrix and an upper triangular Matrix while in case of L decomposition we are decomposing a matrix into lower triangular Matrix and an upper triangular Matrix so here you can see that we no longer have this idea of orthogonal matrix but instead of that we are talking about lower triangle Matrix so in that aspect uh L DEC composition is different from QR DEC composition so what the Lu DEC composition does is that it facilitates the solving of linear equations and Matrix inversions it is common in engineering and in physical sciences for systems of this linear equation to be solved by using lud de composition and in fact if you are learning Quantum uh mechanics that this Lu decomposition can definitely help you to better understand many Concepts but if your target fields are machine learning deep learning or artificial intelligence then for those using QR de composition will be uh much more often a case than using this L de composition let’s now talk about the singular value de composition so what the VD does is that it decomposes a matrix into three matrices so first one is the orthogonal Matrix U the second one is a diagonal matrix and then the third one is this V Star which is the conjugate transpose of an orthogonal Matrix so for now this might seem bit complex and you can see that unlike the QR or Lu de composition where we got just uh two uh matrices as a result of our de composition in case of SD we got three matrices like the name suggest two by the way so three parts and this might seem bit complex but we are going to go through this process step by step and I’m going to provide you detailed example such that this will all make sense but for now let’s focus at the highight level usage of SVD so singular value decomposition is one of the most popular decomposition techniques and it is also directly used as part of machine learning algorithms to form uh those machine learning algorithms it is also used in the data compression in the noise reduction so when we are trying to clean our data and remove the Noise by using SVD because SVD can help us to identify those outliers and then remove them from the data by performing noise reduction and it is also used in the principal component analysis the PCA the uh same dimensionality reduction technique that I just uh mentioned related to Theon de composition because SVD and the ion de composition are highly related to each other so this SVD is used as part of this PCA algorithm and PCA is the most popular the infamous dimensionality reduction technique that is used both in the advanced statistical studies in the statistics in general also in finance and is also used as part of many machine learning and deep learning applications so knowing PCA is a must if you want to get into uh data analytics or data science machine learning and AI but also uh it helped you it will help you also to uh understand uh many other Concepts when it comes to these fields so the SVD provides insight into the structure but also the rank of the Matrix so we are going to see this as part of our example two let’s now also briefly talk about the igon de composition so igon de composition which is highly related to these concepts of igon values and igon vectors it decomposes a matrix into this igon values and ion vectors which then shows the matrices fundamental properties which are related to this idea of correlation what kind of information does this uh Matrix contain what is the variation in what direction is the variation the largest and this ion de composition which is then related to also this idea of SVD and in general this dimensions and correlations is critical for understanding linear Transformations the stability analysis and systems of differential equations but beside this uh mathematical side of uh Concepts and understanding these mathematical topics the ion de composition is also the basis for many algorithms in numerical linear algebra uh but also many applied linear algebra topics like in the data science in machine learning and is used heavily in artificial intelligence for feature extraction for dimensionality reduction related again to the concept of PCA because PCA is based entirely on this concept of I their composition PCA is the direct result of computing the igon values and ion vectors so without knowing what our Dion values and icon vectors you cannot perform PCA because the first step of the PCA is the computation of the icon values and ion vectors and then using different rules which we are referring as the elbow rule or Ka rule we can then use these icon values and icon vectors to understand what are the features in our data that contain the most variation so the most information and then we can use that in order to understand what are the most important features in our data and reduce the dimension of our model by selecting these most important features because what PCA basically does is that it it uses this icon values and icon vectors to understand how we can uh create a linear combination out of our features and understand the the amount of those linear combinations that contain the most variation and then select those and uh select the largest amount of information in the data and then Skip and drop those uninformative being your combinations while still keeping the most information and this definition of the most will then be decided by this differ ruls this is just higher level Insight background information on what you can expect when you are talking about applying this highly technical linear algebra concept of ion de composition into an applied science Fields like data science or machine learning or AI but we will see this later and I’ll also make comments regarding this and though PCA won’t be discussed as part of this course because here we are talking about linear algebra but PCA is part of the fundamental statistics course and in there we are no longer providing all these different details on how you can uh perform this ion composition therefore knowing how to perform I and composition will then set you for success to actually understand the mathematics behind the statistical Concepts like PCA and also later on understand how you can use that PCA in a machine learning Concepts and in AI Concepts like outter encoders and how you can relate your um Auto encoders to this concept of PCA how they are related what are their commonalities and what are their differences so everything is about the choice and choosing the right tool for your problem when it comes to the decomposition tools metrix factorization tools we have seen that there are many options and the the question is which one should we pick in what cases so choosing the right tool is really important when it comes to this different metric factorization techniques because there are many choices and each of them they can be used for different sorts of problems so therefore in order to understand which one you need to pick in what kind of cases what kind of requirements you have and what kind of Sol uh problem you are trying to solve that in those cases you will need to have this knowledge that you learn as part of this course in order to make that right choice of the tool so the choice among QR de composition the L de composition the SVD and igen de composition it really depends on your specific problems requirements and the data characteristics so are you dealing with a complex data are you dealing with a simple data with low Dimensions what is the goal that you uh want to uh achieve what is the problem that you are trying to solve is it to uh reduce the dimension of your feature space is it to solve a problem with linear equations is it to solve a quantum mechanics problem or is it to um incorporate this as part of your machine learning algorithm so QR and LU DEC compositions are usually preferred for solving linear systems while SVD and I and compositions they help us for deeper insights when it comes to the data and what kind of information it contains how we can reduce the dimension of the data or how we can use it as part of machine learning algorithm for noise reduction identifying outliers Etc so um this type of algorithms like SVD and ion de composition it helps us to also uh intuitively using geometry and our knowledge of geometry to um visualize the data for instance the PCA helps us to visualize this High dimensional data using just couple of principal components let’s say we have 10 features in our model so we have a dimension of 10 we are in r10 but we want to visualize our data by using PCA we can then reduce the dimension and come up with uh three principal components which are linear combination of our original 10 vectors and then we can use the three principal components to VIs visualize our data in 3D and this basically helps us to geometrically visualize our data and then make presentations make much more sense of our story so to do uh storytelling for our data and uh much more and these two uh models and tools they are invaluable when it comes to uh applications in machine learning in deep learning in data science and artificial intelligence so so matric factorization techniques they are super important when it comes to computational mathematics they are also directly affecting the data science Ai and many other algorithms so they are not only important in terms of the problem that they are trying to solve but also in order to make the computation process so when coding in python or in other programming languages to make that process much more efficient they also help us to uh make these computations efficient and provide insights into different properties that we have in our data as part of this course we are not only going to discuss one but actually three of these four the composition techniques and this metrix factorization techniques in detail we are going to talk about the qard de composition we are going to not just discuss it but uh also to learn it step by step and we are going to do a detail example with all this steps involved such that you will feel confident doing a QR de composition all by yourself then we are also going to do an SVD DEC composition as well as igon DEC composition and then we are again going to discuss them in terms of their mathematical formulation the definition but also the application stepbystep process and a detailed example such that you can conduct each of those metrix factorization techniques and these decomposition techniques by yourself manually doing all these calculations this understanding and this examples and this Concepts will help you to not just be able to formulate what these techniques are about but really and truly understand and then use them later on whether when doing your own research writing scientific papers or tweaking the algorithm all by yourself when inventing new algorithms I won’t be discussing this L de composition technique because we already know uh that the QR and LU they are both used for similar type of problems therefore to save us time I have selected carefully the uh most important the composition techniques and metrics soriz techniques that you will most likely be dealing with will be dealing with in your future career in applied sciences
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!
The initial source, “01.pdf,” details an investigation of a database schema, focusing on understanding table relationships and performing revenue calculations. It demonstrates how to join tables to incorporate customer and product information, filter data for recent sales, and categorize customers based on revenue using case statements. The subsequent sections introduce the concept of pivoting data using aggregation and case statements, illustrating techniques for analyzing customer counts by region and calculating net revenue across different categories and years. Further content explores statistical functions within pivoting for median sales analysis and advances into segmentation using multiple conditions within case statements for detailed revenue breakdowns. The final portion of the provided text transitions into date calculations, covering functions like date_trunc and date_part for time series analysis, extracting date components, and using intervals and the age function to analyze processing times. This culminates in an introduction to window functions, explaining their syntax and application in calculations over partitions of data without collapsing rows, including ranking and running aggregates, and finally examining frame clauses for controlling the data within a window.
Source Material Study Guide
Quiz
Explain the purpose and importance of the %sql magic command in the provided text. What happens if you try to run a SQL query without it?
Describe what magic commands are in the context of the source material. Give at least two examples of magic commands mentioned besides %sql and explain their function.
What is the Contoso database, and what are some of the key tables within it that are discussed in the excerpts? Briefly describe the purpose of the Sales, Customer, and Date tables.
Explain how net revenue is calculated in the context of the Sales table. What columns are used in this calculation, and why is net price used instead of unit price?
Describe the process of joining tables in SQL as demonstrated in the excerpts. What type of join is frequently used, and on what columns are the tables typically joined in the examples?
What is a CASE WHEN statement, and how is it used in the provided text? Give an example of how it’s used to categorize data within a SQL query.
Explain the concept of pivoting data as introduced in the “pivoting with case statements” section. How is the COUNT(DISTINCT CASE WHEN … END) syntax used to achieve this?
Describe the DATE_TRUNC and EXTRACT functions as explained in the text. What are they used for, and what are some examples of date parts that can be extracted?
Explain the purpose and basic syntax of a Common Table Expression (CTE). How are CTEs used to structure more complex SQL queries in the examples provided?
Briefly describe the functionality of window functions as introduced in the excerpts. How do they differ from aggregate functions with a GROUP BY clause?
Quiz Answer Key
The %sql magic command is crucial for indicating to the Jupyter Notebook environment that the subsequent lines of code should be interpreted and executed as SQL queries. Without it, the code will be treated as regular Python code, leading to syntax errors and incorrect execution.
Magic commands are special commands in the Jupyter Notebook environment that extend its functionality. Besides %sql, examples include %timeit which measures the execution time of the next line of code, and single % followed by Python code which executes that line as Python without timing.
The Contoso database is the data set used throughout the course. Key tables discussed include Sales (containing transaction information like price and quantity), Customer (containing customer details like name and location), and Date (intended for date-based aggregations but later suggested to be ignored for learning date functions).
Net revenue is calculated by multiplying the quantity of a product by its net price and the exchange rate. The net price is used because it represents the actual price charged to the customer after all discounts and adjustments.
Joining tables combines rows from two or more tables based on a related column. Left joins are frequently used to keep all rows from the left table and matching rows from the right table. Tables are typically joined on key columns like ProductKey, CustomerKey, and date columns.
A CASE WHEN statement allows for conditional logic within a SQL query, enabling the assignment of different values based on specified conditions. For example, it’s used to categorize customers as “high” or “low” value based on their net revenue.
Pivoting data transforms rows into columns. The COUNT(DISTINCT CASE WHEN condition THEN column END) syntax is used to count the distinct occurrences of a specific column based on whether a certain condition is met, effectively creating new columns for each category.
DATE_TRUNC extracts a specified date part (e.g., month, year) from a date, while EXTRACT similarly retrieves a part of a date. They are used for analyzing data based on different time granularities. Examples of extractable parts include ‘year’, ‘month’, ‘day of week’.
A Common Table Expression (CTE) is a temporary, named result set defined within the scope of a single query. CTEs are used to break down complex queries into smaller, more manageable, and readable parts, often used before a final SELECT statement or when joining to the same subquery multiple times.
Window functions perform calculations across a set of table rows that are related to the current row, but unlike aggregate functions with GROUP BY, they do not collapse the rows into a single output row. They allow for calculations like running totals, rankings, and averages within partitions of data.
Essay Format Questions
Discuss the importance of using magic commands in the context of interactive SQL querying within a Jupyter Notebook environment. How do they facilitate the integration of SQL with other programming languages like Python, as suggested in the excerpts?
Analyze the strategy of exploring the Contoso database by examining individual tables (Sales, Customer, Date) and then combining them through joins. What are the benefits and potential challenges of this approach to understanding a new database schema?
Evaluate the use of CASE WHEN statements in SQL for data categorization and pivoting, as demonstrated in the source material. Provide examples of scenarios where these techniques would be particularly valuable for data analysis and reporting.
Compare and contrast the DATE_TRUNC and EXTRACT functions for manipulating date data in SQL. In what situations might one function be preferred over the other, and how do they contribute to more effective time-based analysis?
Explain the role and advantages of using Common Table Expressions (CTEs) in writing complex SQL queries. How do CTEs improve query readability and maintainability, and can you provide a hypothetical example (based on the source material) where a CTE would significantly simplify a query?
Glossary of Key Terms
Magic Command: Special commands in interactive environments like Jupyter Notebooks that provide extra functionality beyond the standard language syntax (e.g., %sql, %timeit).
SQL: Structured Query Language, a standard language for accessing and manipulating databases.
Jupyter Notebook: An interactive web-based environment for creating and sharing documents that contain live code, equations, visualizations, and narrative text.
Database: An organized collection of structured information, or data, typically stored electronically in a computer system.
Table: A structure within a database that organizes data into rows and columns.
Column: A vertical attribute or field in a table, containing a specific type of data for each record.
Row: A horizontal record in a table, representing a single instance or entry.
Query: A request for data or information from a database.
Syntax: The set of rules that govern the structure and format of statements in a programming or query language.
Autocomplete: A feature where the environment suggests or automatically completes code as the user is typing.
Syntax Error: An error in the structure or grammar of a statement that prevents it from being correctly interpreted.
Execution Time: The amount of time it takes for a program or query to run and complete.
Net Revenue: The actual revenue received after accounting for discounts, returns, and other adjustments.
Unit Price: The standard price of a single unit of a product before any discounts or adjustments.
Quantity: The number of units of a product.
Join: An SQL operation that combines rows from two or more tables based on a related column.
Left Join: Returns all rows from the left table and the matching rows from the right table. If there’s no match in the right table, NULLs are used for the columns of the right table.
Alias: A temporary name given to a table or column in a query to make it easier to refer to.
CASE WHEN Statement: A conditional expression in SQL that allows for different results based on specified conditions.
Pivoting: A data transformation technique that rotates rows into columns.
Aggregation: The process of summarizing data using functions like COUNT, SUM, AVG, MIN, and MAX.
DATE_TRUNC: An SQL function that truncates a timestamp or date value to a specified precision (e.g., day, month, year).
EXTRACT: An SQL function that retrieves a specific component (e.g., year, month, day) from a date or timestamp value.
CAST: An SQL operator used to change the data type of an expression.
Common Table Expression (CTE): A temporary, named result set defined within the execution of a single SQL statement.
Window Function: An SQL function that performs a calculation across a set of table rows that are related to the current row, without collapsing the rows.
Partition By: A clause used with window functions to divide the rows into partitions within which the function is applied.
Order By: A clause used to sort the rows within a result set or within a window function’s partition.
Jupyter, SQL, and Database Exploration with PostgreSQL
## Briefing Document: Analysis of Provided Sources
This briefing document summarizes the main themes and important ideas presented in the provided excerpts from “01.pdf”. The excerpts cover a range of topics related to using Jupyter Notebooks with SQL, exploring a database (Contoso), performing various SQL operations (including joins, aggregations, window functions, pivoting, date manipulation, and query optimization), and finally, setting up a local PostgreSQL environment with tools like pgAdmin and DBeaver for more robust database interaction and project management.
**Main Themes:**
1. **Introduction to Jupyter Notebooks and SQL Integration:** The initial sections focus on using Jupyter Notebooks with SQL through “magic commands” like `%sql`. This integration allows for writing and executing SQL queries directly within a Python environment.
* **Key Idea:** The `%sql` magic command is crucial for executing SQL within a Jupyter Notebook cell. Without it, SQL syntax will be highlighted as incorrect and will result in errors.
* **Quote:** “very important that you put these magic commands up at the top now so people don’t think i’m crazy magic commands are the actual official language of this”
* **Key Idea:** Jupyter Notebook also supports other magic commands like `%timeit` for measuring code execution time, demonstrating the versatility of the environment. Single `%` applies the command to one line, while `%%` can apply to an entire cell (though not explicitly shown in the excerpt).
2. **Exploring the Contoso Database Schema:** The sources introduce the Contoso database as the primary dataset for the course. The excerpts detail the exploration of key tables like `Sales`, `Customer`, and `Date`.
* **Key Idea:** Understanding the relationships between tables (e.g., `Date` table related to `Sales` via date columns, `Customer` and `Product` tables linked to `Sales` via keys) is fundamental for querying and analysis.
* **Quote:** “last table to explore is that date table this is related using that date column here to the sales table order date and delivery date.”
* **Key Idea:** The `Date` table, while useful for quick filtering in tools like Power BI, will be largely ignored in the course in favor of learning more flexible date functions in SQL.
3. **Performing Fundamental SQL Operations:** The excerpts illustrate core SQL concepts such as calculating net revenue, joining tables to combine data from different entities, and using aliases for tables and columns.
* **Key Idea:** Net revenue is calculated as `quantity * net_price`. The `net_price` already accounts for discounts and promotions.
* **Quote:** “the net price is the price after all the different discounts promotions or any adjustments so basically it’s what we actually charge to the customer when they pay for the product”
* **Key Idea:** `LEFT JOIN` is used to combine tables while ensuring all rows from the left table are included. Aliases (e.g., `s` for `Sales`, `c` for `Customer`, `p` for `Product`) improve query readability.
4. **Introduction to Pivoting Data with `CASE` Statements:** The sources introduce the concept of pivoting data, transforming rows into columns. This is achieved using `CASE WHEN` statements combined with aggregation functions like `COUNT` and `SUM`.
* **Key Idea:** `CASE WHEN` allows for conditional logic within SQL queries, enabling the creation of new categories or columns based on existing data.
* **Quote:** “we’re going to be using statements like case when and aggregation in order to pivot data but what the heck is pivoting data let’s take a look at this simple example”
* **Key Idea:** Pivoting can be used to create summary tables where values from one column become headers in the output.
5. **Date Manipulation with Functions like `DATE_TRUNC` and `TO_CHAR`:** The excerpts demonstrate how to extract specific parts of a date (e.g., month, year) using functions like `DATE_TRUNC` and `EXTRACT`, and how to format dates into desired string representations using `TO_CHAR`. Casting data types (e.g., to `DATE`) is also shown.
* **Key Idea:** `DATE_TRUNC` allows truncating a date to a specified level of precision (e.g., month).
* **Quote:** “specifically if you just want to specify one attribute you want to extract out of it such as something like month as we did you could either do quarter year decade century or even millennium”
* **Key Idea:** `TO_CHAR` provides more flexible date formatting options using various format codes.
6. **Introduction to Window Functions:** A significant portion of the excerpts is dedicated to introducing window functions. These functions perform calculations across a set of rows that are related to the current row, without collapsing the rows like `GROUP BY`.
* **Key Idea:** Window functions use the `OVER()` clause to define the “window” of rows for the calculation. `PARTITION BY` divides the data into groups, and `ORDER BY` orders the rows within each partition.
* **Quote:** “they let you perform calculations across a set of tables related to the current row…and like we showed they don’t group the results into a single output row this is very beneficial as we’re going to demonstrate some future exercises”
* **Key Idea:** Examples include calculating running totals, ranks (`ROW_NUMBER`, `RANK`, `DENSE_RANK`), and moving averages using frame clauses (`ROWS BETWEEN …`).
7. **Lag and Lead Functions:** The excerpts introduce `LAG` and `LEAD` functions, which allow accessing data from previous or subsequent rows within a window partition. This is useful for calculating differences or growth rates over time.
* **Key Idea:** `LAG(column, offset, default)` retrieves a value from a row `offset` rows before the current row. `LEAD` works similarly for subsequent rows.
* **Quote:** “these type of things in a window function allow us instead of looking at the current row to allow us to look at things like the row above it or the row below it”
8. **Frame Clauses in Window Functions:** The sources explain how frame clauses (`ROWS BETWEEN`) within the `OVER()` clause can further define the set of rows to be considered for a window function calculation (e.g., a moving average over the preceding three months). `CURRENT ROW`, `PRECEDING`, and `FOLLOWING` are key keywords.
* **Key Idea:** Frame clauses allow for flexible calculations based on a sliding window of rows.
* **Quote:** “this allows us to specify a physical offset from the current row such as maybe the three preceding rows or maybe the two following rows”
9. **Setting Up a Local PostgreSQL Environment:** The later excerpts transition to setting up a local PostgreSQL database, including installing the server and pgAdmin (a GUI administration tool).
* **Key Idea:** Having a local database environment allows for more hands-on practice and development without relying on remote systems.
* **Key Idea:** pgAdmin is used for managing the PostgreSQL server, creating databases, running queries, and exploring the database schema.
10. **Introducing DBeaver as an Alternative Database Tool:** DBeaver is introduced as a more versatile database management tool that can connect to various database systems, unlike pgAdmin which is specific to PostgreSQL.
* **Key Idea:** DBeaver offers a more comprehensive set of features for database development and administration, including project management, SQL editing enhancements (auto-completion, formatting), and data export/visualization capabilities.
* **Quote:** “dbeaver now this is a database management tool so can only connect to different [types of databases]”
11. **Project Management in DBeaver:** The excerpts demonstrate how to create projects in DBeaver to organize SQL scripts, bookmarks, and other related files. This helps in structuring database development work.
12. **Introduction to Views:** Views are introduced as virtual tables that represent the result of a stored query. They simplify complex queries and provide a level of abstraction over the underlying tables.
* **Key Idea:** Views are created using the `CREATE VIEW` statement and can be queried like regular tables.
* **Quote:** “it’s a virtual table that allows us to show the results of a stored query in it”
13. **Introduction to VS Code for Project Development:** VS Code is presented as a powerful code editor, not just for SQL but also for creating and managing project documentation (like README files in Markdown). Its preview capabilities for Markdown are highlighted.
* **Key Idea:** VS Code, with its extensions, provides a robust environment for both code (SQL) and documentation.
14. **Query Optimization with `EXPLAIN` and `EXPLAIN ANALYZE`:** The final excerpts touch upon basic query optimization by introducing the `EXPLAIN` and `EXPLAIN ANALYZE` commands, which provide insights into the query execution plan and performance.
* **Key Idea:** `EXPLAIN` shows the planned steps the database will take to execute a query. `EXPLAIN ANALYZE` actually executes the query and provides timing information.
* **Quote:** “explain demonstrates the execution plan without actually executing it whereas explain analyze basically means like it’s going to analyze it and it actually does execute it”
**Most Important Ideas and Facts:**
* Jupyter Notebooks can seamlessly integrate with SQL using magic commands like `%sql`.
* The Contoso database is the central dataset for learning SQL concepts.
* Understanding table relationships is crucial for effective querying.
* `CASE WHEN` statements are essential for conditional logic and data pivoting.
* Window functions provide powerful analytical capabilities without collapsing rows, enabling calculations like running totals, rankings, and moving averages.
* `LAG` and `LEAD` functions allow for comparisons between rows.
* Frame clauses in window functions define the scope of rows for calculations.
* Setting up a local PostgreSQL environment with pgAdmin and DBeaver provides a robust platform for database learning and project development.
* DBeaver is a versatile database tool supporting multiple database systems.
* Views simplify queries and provide abstraction.
* VS Code is a valuable tool for both SQL development and project documentation (using Markdown).
* `EXPLAIN` and `EXPLAIN ANALYZE` are used to understand and optimize SQL query execution.
These excerpts lay a comprehensive foundation for learning intermediate SQL concepts, ranging from basic query structures and database exploration to advanced analytical functions and development environment setup. The progression through Jupyter Notebooks to local database tools like PostgreSQL and DBeaver indicates a move towards more practical and real-world database interaction and project management.
Exploring Data with SQL Magic and the Contoso Database
1. What is the purpose of the %sql magic command in the provided context?
The %sql magic command is essential for executing SQL queries within the environment (likely a Jupyter Notebook). When placed at the beginning of a cell or line, it signals to the interpreter that the subsequent text should be treated as a SQL query to be run against the connected database. Without this command, the SQL syntax would be misinterpreted, leading to errors. Using two percent signs (%%sql) applies the command to the entire cell, while a single percent sign (%sql) applies it only to the current line.
2. Beyond SQL, what other types of “magic commands” are mentioned and what is their general function?
The text mentions that %sql is not the only magic command available. It specifically highlights the %timeit magic command as an example. The general function of these magic commands is to provide additional functionalities and tools within the coding environment, such as measuring the execution time of code (%timeit) or facilitating interaction with external systems or specific languages (like SQL with %sql).
3. What is the Contoso database and what are some of the key tables within it that are explored in the excerpts?
The Contoso database is the primary dataset used throughout the lessons. The excerpts introduce and explore several key tables: – Sales: This table contains transactional data, including information about orders, quantities, net prices (prices after discounts), and order dates. It’s central to calculating revenue. – Customer: This table holds information about customers, such as their given name, surname, country, continent, and customer key. – Product: This table contains details about the products being sold, including product key, product name, category name, and subcategory name. – Date: This table contains various date-related attributes that can be used for aggregation and filtering based on dates, although the course later emphasizes using date functions instead of relying solely on this table.
4. How is “net revenue” calculated within the context of the Contoso database, and why is it considered important?
Net revenue is calculated by multiplying the quantity of a product sold by its net price (the price after all discounts and adjustments) and the exchange rate. It is considered important because it represents the actual revenue received from customers after accounting for discounts and promotions, reflecting the true value of sales transactions.
5. What is “pivoting data” as described in the excerpts, and how is it achieved using SQL?
Pivoting data involves transforming rows into columns. The example provided shows how to take customer counts grouped by continent (originally in rows) and restructure the output to have each continent as a separate column displaying the total customer count for that continent. This is achieved using aggregate functions (like COUNT DISTINCT) combined with CASE WHEN statements to conditionally assign values to the new columns based on the continent.
6. What is the purpose of the DATE_TRUNC and EXTRACT functions when working with dates, and how do they differ from the TO_CHAR function?
DATE_TRUNC is used to truncate a date to a specified level of precision, such as month, quarter, or year. It returns a timestamp or date with the less significant parts set to the beginning of the time period (e.g., the first day of the month).
EXTRACT is used to retrieve a specific component from a date or timestamp, such as the year, month, or day. It returns a numeric value representing that part.
TO_CHAR is used to format a date or timestamp as a text string according to a specified pattern. This allows for flexible output formats, such as extracting the month name or formatting the date in a particular way.
While DATE_TRUNC and EXTRACT help in manipulating and retrieving date parts for analysis or grouping, TO_CHAR focuses on presenting date information in a desired textual format.
7. What are “window functions” and how do they differ from standard SQL aggregate functions? What are some examples of window functions discussed in the excerpts?
Window functions perform calculations across a set of rows that are related to the current row, without collapsing the rows into a single output row like standard aggregate functions (e.g., SUM, COUNT, AVG) do. They allow you to access and perform calculations on a “window” of data defined by a PARTITION BY clause (dividing the data into groups) and an ORDER BY clause (specifying the order within each partition).
Examples of window functions discussed include: – Aggregate functions used as window functions (e.g., AVG() OVER (…)). – Ranking functions (ROW_NUMBER(), RANK(), DENSE_RANK()). – Value functions (FIRST_VALUE(), LAST_VALUE(), NTH_VALUE(), LAG(), LEAD()). – Percentile functions (PERCENTILE_CONT()).
8. What is “cohort analysis” as demonstrated in the excerpts, and what kind of insights can it provide about customer behavior?
Cohort analysis involves grouping users or customers based on a shared characteristic, typically the time they acquired a product or service (their “cohort year” or “first purchase date”). It then tracks their behavior over time. The excerpts demonstrate cohort analysis by examining how different cohorts of customers contribute to total revenue and customer retention in subsequent years. This can provide insights into customer lifetime value, the effectiveness of acquisition strategies over time, and customer churn patterns by showing how engagement and spending change for different initial groups of customers.
SQL for Data Exploration: A Course Overview
Based on the sources, data exploration within the context of this SQL course for data analytics appears to be a crucial initial step involving understanding the structure and content of a database using SQL queries and visualization techniques.
Here’s a breakdown of data exploration as presented in the course:
Understanding the Database Structure: The course emphasizes the importance of getting familiar with the database schema, which includes identifying the different tables and understanding how they relate to each other. The Entity Relationship Diagram (ERD) of the “cantazo” database is introduced as a tool to visualize these relationships, particularly how dimensional tables like store, product, and customer relate to the main fact table, sales.
Examining Tables and Columns: Data exploration involves inspecting individual tables to understand the columns they contain and the types of information stored in them. This is demonstrated by using SQL queries like SELECT * FROM sales LIMIT 10 to view the first few rows and identify the available columns such as dates, customer key, store key, product key, quantity, price, cost, and currency information.
Exploring Metadata: The course also shows how to query the information schema, a meta-database, to discover the tables within a database and the columns within each table. Specifically, it demonstrates using SELECT table_name FROM information_schema.tables WHERE table_schema = ‘public’; to list the tables and SELECT * FROM information_schema.columns WHERE table_name = ‘customer’; to see all the column names in the customer table.
Using SQL for Initial Analysis: Simple SQL queries are used to get a first look at the data and its characteristics. For example, selecting all columns from a table and limiting the number of rows allows for a quick overview of the data’s format and values.
Leveraging Tools for Exploration: The course utilizes Google Colab in the first half, which allows for running SQL queries and provides features like converting query results to interactive tables and generating visualizations. The integration with Gemini AI is also mentioned as a way to assist in generating SQL queries for data exploration. Later in the course, pgAdmin and DBeaver are introduced as more advanced database tools that allow for visual exploration of the schema, tables, and data. DBeaver, in particular, is highlighted for its ability to view table data in a grid format and examine ER diagrams.
Understanding Data Relationships through Joins: As part of data exploration, the course demonstrates how to use JOIN clauses (specifically LEFT JOIN) to combine data from multiple related tables, such as sales, customer, and product, to understand how different entities interact and to bring together relevant attributes for analysis.
Identifying Key Fields: The initial exploration helps in identifying key fields that will be important for further analysis, such as the different keys used to relate tables and the metrics (e.g., quantity, net price) available for calculations like net revenue.
In essence, data exploration in this course lays the foundation for more advanced data analytics by ensuring a solid understanding of the available data, its structure, and its basic characteristics through the use of SQL and database exploration tools. This initial phase is crucial for formulating meaningful analytical questions and developing effective SQL queries for deeper insights.
SQL for Time Series: Date Calculations
Based on the sources, this SQL course includes a chapter dedicated to date calculations, emphasizing their importance for time series analysis. The course covers several key date and time functions and keywords:
DATE_TRUNC() Function: This function allows you to truncate a timestamp down to a specified level of precision, such as year, quarter, month, week, day, hour, etc.. For example, DATE_TRUNC(‘month’, order_date) extracts the month and year from the order_date. The output of DATE_TRUNC() is a timestamp, which can be cast to a DATE data type if needed using the ::date operator.
TO_CHAR() Function: This function provides a flexible way to format date and time values into strings based on various format patterns. You provide a timestamp or date and a format string to specify the desired output. For instance, TO_CHAR(order_date, ‘YYYY’) extracts the year, and TO_CHAR(order_date, ‘MM-YYYY’) extracts the month and year in the specified format. TO_CHAR() offers more customization compared to DATE_TRUNC() as you can combine different components in your desired order.
DATE_PART() Function: This function extracts a specific component from a date or timestamp, such as year, month, day, hour, minute, second, etc.. The syntax involves specifying the part you want (e.g., ‘year’, ‘month’) as a string and then the source date or timestamp. For example, DATE_PART(‘year’, order_date) extracts the year. The source mentions that the output might include decimals, which might not always be desirable.
EXTRACT() Function: Similar to DATE_PART(), EXTRACT() also retrieves a specific component from a date or timestamp. However, the syntax is slightly different: you specify the part (e.g., YEAR, MONTH, DAY) as an uppercase identifier followed by the keyword FROM and the date or timestamp. For example, EXTRACT(YEAR FROM order_date) extracts the year. The course prefers EXTRACT() over DATE_PART() for components like year, month, and day as it typically returns integer values without unnecessary precision.
CURRENT_DATE: This keyword returns the current date at the time the query is executed, based on the server’s time zone or a specified time zone (though specifying a time zone is optional if the default is sufficient).
NOW(): This function returns the current date and time (timestamp) at the moment the query is executed.
INTERVAL Keyword: The INTERVAL keyword is used to represent a span of time, which can be defined in units like days, months, years, hours, etc.. You can create an interval by using the keyword INTERVAL followed by a value and a unit (e.g., INTERVAL ‘5 year’, INTERVAL ‘6 month’). Intervals can be added to or subtracted from dates and timestamps for date arithmetic.
AGE() Function: This function calculates the difference between two timestamps or dates, returning the result as an interval. The order of the dates matters; AGE(end_date, start_date) will yield a positive interval. You can then extract specific components from the resulting interval, such as the number of days, using the EXTRACT() function.
The course also demonstrates how these date functions are used in conjunction with other SQL clauses for analysis:
Filtering Dates with WHERE Clause: Date functions are commonly used in the WHERE clause to filter data based on specific date ranges or conditions. Examples include filtering orders within a specific year using EXTRACT(YEAR FROM order_date) = 2023 or finding orders within the last 5 years using order_date >= current_date – INTERVAL ‘5 year’.
Grouping by Date Components with GROUP BY Clause: Functions like DATE_TRUNC() or TO_CHAR() are useful for grouping data by specific time periods, such as monthly sales by grouping on DATE_TRUNC(‘month’, order_date) or TO_CHAR(order_date, ‘MM-YYYY’).
Ordering by Date with ORDER BY Clause: Dates can be used in the ORDER BY clause to sort results chronologically.
Calculating Time Differences: The AGE() function is used to calculate the duration between events, like the processing time of an order by finding the age between the order date and the delivery date.
The importance of dynamic filtering using functions like CURRENT_DATE and INTERVAL is highlighted, as it allows for creating queries that automatically adjust based on the current time, such as always retrieving data for the last 5 years.
SQL Course: Calculating Net Revenue
Based on the sources, net revenue in this SQL course is consistently calculated by taking into account the quantity of items sold, the net price of each item, and the exchange rate if currency conversion is needed.
Here’s a breakdown of the net revenue calculation process as described in the sources:
Net Price Defined: The net price is the price that the customer actually pays for a product after all applicable discounts, promotions, or adjustments have been applied. It is explicitly stated that the net price is less than the unit price due to these reductions.
Basic Calculation: The fundamental way to calculate the net revenue for a particular transaction is by multiplying the quantity of the product purchased by its net price. This can be represented as:
Net Revenue = Quantity * Net Price
Incorporating Exchange Rates: In the context of the “cantazo” database used in the course, the transactions may involve different currencies (e.g., pounds and US dollars). To standardize the revenue in a common currency (like US dollars, as the instructor prefers), an exchange rate is applied. The complete formula for net revenue used throughout the course is:
Net Revenue = Quantity * Net Price * Exchange Rate
This formula is used in various lessons when calculating total revenue, revenue by category, customer lifetime value, and for cohort analysis.
Example of Currency Conversion: Source provides an example where revenue figures are initially in pounds and then converted to US dollars by multiplying by an appropriate exchange rate.
Application in SQL Queries: The course demonstrates the use of this net revenue calculation within SQL SELECT statements, often with the result being aliased as net_revenue or total_net_revenue. This calculation is then used in aggregations with the SUM() function to find total revenues for different groupings of data (e.g., by order date, category, customer cohort).
Therefore, to calculate net revenue in the context of this course and the “cantazo” database, you generally need to multiply the quantity of the products sold by their respective net prices, and then adjust for currency differences by multiplying by the relevant exchange rate. The course emphasizes that the net price already reflects any discounts or adjustments, representing the actual amount charged to the customer.
Customer Segmentation: A Data-Driven Approach
Based on the sources, customer segmentation is a key data analytics concept that involves dividing customers into distinct groups based on shared characteristics or behaviors. The goal of customer segmentation is to enable more targeted analysis and tailored strategies for different customer groups.
Here are the main aspects of customer segmentation discussed in the sources:
Definition: Customer segmentation involves taking large datasets and breaking them down into smaller, more manageable pieces to analyze different behaviors within those groups. This allows for a deeper understanding of customer behavior and facilitates more effective decision-making.
Methods using CASE WHEN Statements: The course emphasizes using the CASE WHEN statement as a fundamental tool for customer segmentation. This allows for the creation of new columns that categorize customers based on specified conditions.
Simple Binary Segmentation: Customers can be segmented into two groups, such as “high value” and “low value,” based on a single criterion like net revenue threshold (e.g., above or below $1,000).
Segmentation by Multiple Conditions: More advanced segmentation can involve multiple conditions using the AND operator within a CASE WHEN statement. For example, segmenting customers based on a combination of the year of purchase and whether their net revenue is above or below the median.
Segmentation into Multiple Tiers: Customers can be divided into more than two segments (e.g., low, medium, high value) using multiple WHEN clauses within a single CASE block. This allows for a more granular understanding of customer value.
Segmentation based on Net Revenue and Spending: A primary method for customer segmentation in the course involves analyzing customer spending, often using net revenue as the key metric.
Segmentation using Percentiles: The course demonstrates segmenting customers into tiers (low value, mid value, high value) based on their total lifetime value (LTV) using percentiles (25th and 75th). Customers falling below the 25th percentile are categorized as “low value,” those between the 25th and 75th percentiles as “mid value,” and those above the 75th percentile as “high value”.
Purpose of Segmentation: The primary goals of customer segmentation highlighted in the sources include:
Identifying Valuable Customers: Understanding who the most valuable customers are based on their spending or LTV.
Targeted Marketing: Enabling businesses to target specific customer groups with marketing campaigns tailored to their needs and value.
Analyzing Group Behavior: Facilitating the analysis of different customer groups to understand their spending habits, retention rates, and other key behaviors.
Developing Business Strategies: Providing insights that can inform business decisions and strategies for customer engagement, retention, and growth.
Implementation in SQL: The process of customer segmentation typically involves:
Calculating relevant metrics like total net revenue or lifetime value.
Using CASE WHEN statements to create a new column that assigns customers to different segments based on defined criteria.
Aggregating data by these segments to analyze their characteristics, such as total revenue contribution, customer count, and average value.
In summary, customer segmentation as taught in this course is a crucial analytical technique leveraging SQL’s conditional logic and aggregate functions to categorize customers based on their value and behavior. This process allows for a more nuanced understanding of the customer base and enables businesses to implement more effective and targeted strategies.
SQL Query Optimization: Techniques and Analysis
Based on the sources, query optimization is an important topic covered in the second half of this SQL course. The goal of query optimization is to improve the performance and efficiency of SQL queries, making them run faster and consume fewer resources.
Here’s a breakdown of the key aspects of query optimization discussed in the sources:
Understanding the Execution Plan with EXPLAIN: The course emphasizes the use of the EXPLAIN keyword to understand how the database plans to execute a query.
EXPLAIN shows the execution plan without actually running the query. This plan details the steps the database will take, such as table scans and joins.
EXPLAIN ANALYZE goes a step further by executing the query and providing actual execution times, planning time, estimated costs, number of rows processed, and other statistics. This allows for a more precise understanding of query performance. The output of EXPLAIN ANALYZE can help identify bottlenecks in a query.
The output of EXPLAIN and EXPLAIN ANALYZE includes details about the cost (an arbitrary unit assigned by PostgreSQL), the estimated number of rows, and the width (row size in bytes) for each step in the execution plan.
DBaver provides a feature to visualize the execution plan, offering another way to understand the query execution flow.
Query Optimization Techniques: The course covers various techniques to optimize SQL queries, categorized as beginner, intermediate, and advanced.
Beginner Techniques:
Using LIMIT: Employing the LIMIT clause to restrict the number of rows returned can significantly reduce query execution time, especially when dealing with large tables and only a subset of data is needed. The sources demonstrate a substantial decrease in execution time when LIMIT is used.
Being Selective with Columns (SELECT Specific Columns vs. SELECT *): While PostgreSQL might sometimes efficiently retrieve data using SELECT *, it’s generally recommended to select only the specific columns required for the analysis. This practice can be more efficient, particularly in large databases, by reducing the amount of data that needs to be processed and transferred.
Using WHERE Instead of HAVING: Filtering data using the WHERE clause before aggregation (with GROUP BY) is generally more efficient than filtering the aggregated results with the HAVING clause. The WHERE clause reduces the number of rows that need to be processed by the aggregation step.
Intermediate Techniques:
Minimizing GROUP BY Operations: Reducing the number of columns in the GROUP BY clause, especially if grouping by columns that have repeating values within the context of the aggregation, can lead to performance improvements. The course demonstrates that removing an unnecessary column from the GROUP BY clause can decrease execution time. In cases where seemingly redundant GROUP BY columns exist, using aggregation functions like MAX() on those columns can help minimize the GROUP BY while preserving the desired information.
Reducing JOIN Operations: Minimizing the number of JOIN operations and considering the type of JOIN used can impact query performance. Using functions to extract necessary information instead of joining tables can sometimes be more efficient. Additionally, using more specific join types like INNER JOIN when all matching records are expected in both tables can be slightly more performant than less restrictive joins like LEFT JOIN.
Optimizing ORDER BY Clauses: Optimizing the ORDER BY clause involves limiting the number of columns being sorted, avoiding sorting on computed columns or function calls if possible, and sorting by the most selective columns first. Utilizing database indexes for sorting can also be beneficial, although index management is typically handled by database administrators.
Advanced Techniques:
These include using proper data types, implementing indexing on frequently queried columns to speed up data retrieval, and employing table partitioning for very large tables to improve query performance. These techniques are often managed at the database administration level.
By understanding and applying these query optimization techniques, along with analyzing the execution plan provided by EXPLAIN and EXPLAIN ANALYZE, users can write more efficient SQL queries that perform better, especially when working with large datasets.
SQL for Data Analytics – Full Intermediate Course
The Original Text
data nerds welcome to this full course tutorial on intermediate sql for data analytics this is the course for those that understand the basics of sql but want to take it to the next level perfect for those that took my first course on this now to master this tool we’ll break down more advanced sql concepts in short 10-minute lessons during this you’re going to be working right alongside me completing realworld exercises following each lesson you’ll have the option to do interview level practice problems to not only prep you for the job but also reinforce your learnings and by the end of the course we’ll have used sql to build a fully customizable portfolio project that you can share to demonstrate your experience now sql is by far the most popular tool of data analysts for those in the united states it’s the top skill that’s in almost half of all job postings for data analysts and this only increases in demand for senior data analyst roles coming in at two out of every three job postings now in related data jobs like data engineers it’s almost the same appearing in two of three job postings and for data scientists it’s in almost half now sql or sql is the language used to communicate between you and a database it’s my mostused tool as data analyst starting with my first job working for a global fortune 500 company and even to my most recent role working with mr beast yeah even jimmy uses it this tool is so imperative i use it all the time with python excel powerbi and tableau to connect to my databases so over the years i’ve been cataloging everything i found helpful with using this tool and i put it all into this course now you’re probably wondering who is this course for well if you’re unfortunate to take my first course here’s some items you should definitely know keywords used for data retrieval functions and keywords used for aggregations and grouping the different types of joins and also unions keywords used for logic and conditions along with date manipulation data schema control and finally subqueries and cte now as far as the math required to take the course if you have a secondary education such as high school in the united states you have the requisite knowledge to take this we’re going to be doing at most just some basic algebra and statistics now let’s get into the course structure we’re going to be breaking this down into two halves in the first half we’ll have an intro that will get you set up and comfortable with the database we’ll be using throughout the entire course next we’ll jump right in pivoting data using case statements we’ll be transforming and analyzing data using aggregation and also statistical methods then we’re going to get into intermediate date and time functions because frankly you can’t get away from date and time data in databases we’ll then wrap up the first half covering window functions the most requested topic i’ve gotten by far on this covering basic and also complex aggregations now for the second half of the course we’re going to shift gears we’re going to not only install postgress on your machine but also we’re now going to be working in these lessons to building our portfolio project we’ll start by setting up the database locally and installing a top editor for running sql queries with this environment set up we’ll build our first view and this will actually help us solve our first portfolio problem after this we’ll transition into learning the most popular functions to transform messy data to solve our second portfolio project problem and then we’ll wrap all this up with query optimization understanding how to use keywords like explain to optimize queries so by the end of this you’ll have a real world project to showcase your newfound skills and demonstrate your experience now i’m a firm believer in open sourcing education and making it accessible to everyone so this course is completely free i’ve linked all the resources you need below including the sql environment and all the different files you need to run the queries remotely and locally oh and also include my final project that you can also model after now unfortunately youtube isn’t paying the bills like it used to so i have an option for those that want to contribute and thus help support fund more future tutorials like this for those that use the link below to contribute you’re going to get some more additional resources specifically after each lesson you’re going to have access to interview level sql problems it will not only reinforce your learnings but also prep you for job interviews in here you’re going to get community access to be able to ask any questions to fellow students along with access to the queries and notes behind each lesson so you can follow right along as i go through it finally at the end you’ll receive a certificate of completion that you can share to linkedin now for those that have bought those supporter resources you’re going to continue watching the course here on youtube but then you can go to my site to actually work through all these problems access to the notes and access to community all right we’re about to get into the first lesson before we do that i want to cover some common questions and answers specifically we’re going to start with this one first what database are we even using well every year stack overflow interviews a bunch of nerds to find out what are their top technologies that they’re using and 50,000 chose that postgress was their top option to use and to use over the coming year and according to this visual it’s not only the most admired it’s the most desired to learn database so for this course we’re going to be using and learning with postgress now that we know the database how the heck are we going to be running these sql commands well as i mentioned previously this course is broken into two halves and we’re going to be using an option for the first half that gets you up and running quick specifically we’re going to be using google collab which is a free option and it allows us to have an environment that we can not only load the database in but also query it i’ve linked this notebook below and includes all the code necessary to install this database and get into querying it now don’t worry if you haven’t used collab before i’m going to break it down all in the next lesson which for those that bought the course perks you’re going to get access to these lessons which are in a jupyter notebook for the second half of the course we’re going to shift gears and we’re going to install postgress locally on your computer and run all the queries from there we’re going to get you set up with pg admin which is postgress’s custom guey in order to interact with databases but from there we’re going to get you set up with the most popular database editor dbaver which is used by over 8 million users and this is where we’re going to be running our queries and i like this editor because it’s not only free but it also connects to a host of different databases so whatever you use and learn in this course with this editor you can apply to other databases now that we know the database and the editor what data set are we going to be using for this well i present to you cantazo and this is a data set created by microsoft used to imitate real business data jumping back into dbaver we can see the erd or entity relationship diagram and this shows how the data set revolves around sales data that’s the fact table and then we also have four dimensional tables that relate to it this is going to be great for analyzing business transactions in a real world scenario we’re going to go over everything you need to know for this after our google collab lesson now that we got that out of the way let’s get into some resources you have available starting with those that have decided to support the course first i’m going to walk you through how to get access to the course notes which detail all the different topics and code that i use within each lesson and next you’re going to have access inside of the course platform to interview level sql practice problems after each lesson i’m going to provide you with a bunch of different practice problems that range in difficulty for you to go through and test your skills if you get stuck feel free to jump in the comment section below and talk with other students in the course speaking of help how the heck do you get help in this course well you could jump into the youtube comment section and hope somebody comes and actually answers your question or you can get a really quick answer going to a reputable chatbot like chatgbt i use this bad boy all the time with my coding issues and it gets you an answer quick all right next question well isn’t really a question it’s more of a statement people tell me all the time luke this video is too long i can’t navigate it well unfortunately i think you don’t know how first of all i include chapter markers for all the different lessons throughout this the next is keyboard shortcuts i like to use j and k in order to jump forward or backwards 10 seconds and then finally if you need more precise navigation you can just click and drag up on the navigation bar of the video itself and then you can do precise seeking pretty cool all right last question who helped build this course and i’d be remiss if i didn’t give a shout out to kelly adams she was the brains behind putting together the lesson and also a lot of the practice problems for this this course wouldn’t have been possible without the help of her all right let’s get into the first lesson all right in this lesson we’re going to be going over how we’re going to be running sql queries in this first half of the course using google collab which is a type of jupyter notebook so link below is a blank notebook and opening up it’s not fully blank but it’s blank enough to actually get started with writing sql queries let’s do a quick demo of how we’re going to use this for sql queries first i need to run this cell up top and it’s going to give me this warning that hey this notebook was not authored by google it’s fine it’s run anyway it’s from me you can trust me it should take about 40 to 50 seconds to run this cell which we’ll go through more later in this video basically it’s loading the database and getting it set up for us to actually use and now run sql commands so inside this code cell let’s provide a command so we’re going to begin by writing our command underneath this percent sql syntax right here at the top and i’ll provide this query looking into the sales table looking at those top 10 options i can run it by pressing this play button or pressing shift enter in less than a second i have all the different results pictured below if i want to run another cell i can just come underneath it click code make sure that i add that percent sequel to the top of the cell it’s not going to work otherwise and then run my next command that i want to right underneath this all right with that out of the way we’re going to now dive deeper into understanding what is google collab what are jupyter notebooks how to actually use these to run sql queries and what the heck is going on with all that code that i had in those cells now if you have familiarity with using google collab already or already confident in using jupyter notebooks and you feel like any of this that i’m going to cover is not relevant to you it’s fine go ahead skip to the next lesson this is more focused on those that don’t have any background with using jupyter notebooks so let’s start with jupyter notebooks here i have a jupyter notebook of this actual lesson inside of vs code don’t worry you don’t need to actually open inside vs code just showing this for demonstration purposes now personally i love jupyter notebooks for performing analysis because not only can i have these text cells like are pictured right here and then scrolling down even further i can see that at the bottom i have a sql cell along with the sql output so i love these because i can use sql to extract out and analyze the data i need and then if needed use something like python to visualize it now moving into google collab which you can see right here i’m inside my web browser and this is that same exact file that i had inside of vs code but now it’s here inside of google collab and similarly it has that same functionality where i can write python code in cells along with using that sql and the outputs of that below it i really like google collab because it makes it super easy to share and collaborate with others this isn’t just a static document i can come in here and actually run all the different cells inside of this notebook and if somebody wanted to they could come in and modify this query further so right now this one’s only looking at years let’s say we wanted to look at the actual total revenue i could just add this line in the command run it and get the results right below so super easy to collaborate with others and now you may be wondering why are we actually using collab for running these sql commands well basically this code right here that i have in this cell that we’re going to cover i promise allows us to load in our database and for you to have access to the database immediately without having to actually install it locally on your own computer so basically we can get up and running with running all these different sql commands really quickly let’s start with a blank notebook to walk through this process of understanding how to use notebooks if you navigate to collab.resarch.google.com this is where we’re going to start a new notebook and it will have prompted you to log into google at this point anyway go and click this so it starts this new one which gives the title untitled zero you can go up up here and actually change it and i’ll change it something like collab 101 quick overview before diving into the center portion right here we have a typical menu up at the top to do a bunch of different options and then we also have this sidebar over to the left hand side that gives us a lot of different options as well in the center here is where the actual notebook is itself and i can do things like either add a code cell or a text cell if i wanted to i could type into it this is a text cell i can also change the formatting of it by highlighting it and toggling it to being a heading they also have multiple other options available as well whenever i’m done with this all i have to do is press shift enter and whenever i press shift enter it then starts another cell a coding cell below that now in collab these are exclusively python cells we have to do some magic if you will in order to get it to run sql but you may not realize it but you actually know some python even if you don’t know it i could do something like 2 + 2 press shift enter and what’s going to happen here is it’s going to run the cell of 2 plus 2 and then we get the results of four now if i don’t need certain cells like this one up at the top i just click into it and click the trash can similarly i can do it to this one down below now let’s go over these menus and for this i’m going to be demoing it using the actual lesson plan notebook from this cuz it makes it more interactive to show actually the capabilities of it anyway over on the lefth hand side if i click this over on the left i have the table of contents based on how i formatted all the different lesson notes i can actually scroll through and see all the relevant topics if i wanted to find something i can just go in here type fine of markdown and as expected take me to all the different markdown things inside of here we also have other things like variables secrets and also files that’s more in depth if you’re using python for this you won’t really need to use that along with these three at the bottom also not going to be using as much in this sql course now up at the top in the file menu right here file edit view insert everything like that’s normal runtime is the one location that i find i’m actually using the most and find the most important anytime i’m opening a notebook i’m going to be doing this run all and i can also see that i can do this with the shortcut of command f9 and this will go through and actually run all the cells down here at the bottom it gives you a status update of what’s going on along with the time it’s taking so far now scrolling through all these different cells i can see they all executed properly but sometimes we run into bugs and they’re not running properly in that case we can come up here into runtime and i recommend running this of just restart session and run all it will prompt you if you need if you really want to do this and yes go ahead and do it basically clear everything out and run it again that’s only if you’re having problems you shouldn’t but if you did now you know in this last section of the lesson let’s understand what is going on with how we’re running sql queries inside of this notebook for this i want you to actually open up that blank sql notebook and load it into your window and you can follow along with me if you haven’t done it already go ahead and up at runtime click run all so i mentioned earlier all of this code here which is in python goes through and actually installs and sets up your database we’re going to walk through it really quickly but the important thing to understand here is not necessarily the code or that you need to code it yourself it’s mainly understand what’s going on behind the scenes first it goes in and imports some important libraries that we need for this next if it’s in collab which we’re in we go in and install postgress so postgress is actually running inside of this environment that we’re inside of it goes through and sets up a user a password and then from there actually installs the database itself which you can get at this link right here from there we import in a sql library in order to be able to run sql commands specifically it’s called gps sql and then with this jubsql we go ahead and load the extension actually connect to this database that we loaded in from up above and do some other fancy things that help us get formatting and everything else set up properly so similar before below this magic command of percent sql i can write a sql query as i’m writing these sql commands you should have autocomplete come up so in this case i have select if i want to use it all i have to do is press tab and then once i have everything i need there once again i can press shift enter now that magic command is really important if i were to copy this paste it below one i get all of this highlighting saying that it’s misspelled and that they have syntax errors and then two when i actually try to run it i get actual syntax errors so very important that you put these magic commands up at the top now so people don’t think i’m crazy magic commands are the actual official language of this and we’re not only limited to sql magic commands they also have a host of other ones let’s say i want to use this one of time it where it measures the execution time of the next line of code i could type the magic command of percent time it some help pops up of what actually is going on with this module that we’re actually using here which is pretty actually useful and then underneath it i can put some python in here i’ll just do something simple like 2 plus 2 running this pressing shift enter we can see that this special command provides the time of this took 9.93 nanconds now with these magic commands you can also use just one percent sign and that means it applies only to the line that it’s currently on so in this case i could do 2 + 2 on this line press shift enter it’s still going to run it which in this case looks like it’s a little bit faster but if i actually had only one percent sign and let’s say this is on another line pressing shift enter it’s just going to output the four and it’s not going to actually time it it’s not until i actually use two of the percent times and run it that it will actually time it and now we’re back up to 9.85 nconds so i’m just reinforcing this because it’s very important that you remember to do that percent sql before any sql command now if you’re nerd like me and you want to dive deeper into the documentation of jubsql because of the brains behind that sql magic man you can a link below all right for those that purchased the supported resources you now have some practice problems to go through and get more familiar with how to use jupyter notebooks and sql queries together in the next lesson we’re going to be diving deeper into the database to understand all the different tables and what comes along with it with that i’ll see you in the next one in this lesson we’re going to be getting an intro into the database that we’re going to be using for the entirety of this course specifically the contazo database for this we’re not only going to explore why we’re using this data set but also the components about it exploring all the different tables using things like the erd or entity relationship diagram now we’re going to use this lesson as a warm-up to get ready to get into using intermediate sql so during the course of this i will be covering different past topics that you should know in order to get you up to speed as fast as possible if you haven’t used sql in a while by the end of this we’re going to be covering a query from scratch in order to dive in to the most popular tables while using google’s collab and some additional ai features to speed up your workflow now the contazo database that we’re going to be using for this is based off of a data set from microsoft which they’ve been using for years whenever they launch any products specifically sql products in order for you to explore how to use the functionality of it anyway this database is really robust because it contains a lot of different information in it such as sales transactions product information store details and even date and time data and this database is great because it allows us not only to explore all these different intermediate sql topics that we’re going to be using for this but also it’s based on a real world business set of data so what you’re going to learn in this course you can apply to the real world and so you may be like luke how the heck do i get this database installed well if you remember from the last video we have this python code up at the top that actually goes through and installs the database the database or the sql file for loading it it’s located at this link and we go through this script right here in order to load it in to this collab notebook which i’ve conveniently linked a blank notebook below that you’ll be able to follow along any of the lessons with so this diagram shows via these lines between all these different tables how they are actually related and there’s actually a lot of columns inside of these tables themselves so we put these ellipses at the bottom to basically signify or symbolize all the different columns that are in it so let’s get into breaking this bad boy down we have a total of six tables in this contazo database specifically our main fact table is the sales table and this contains all of our quantitative business metrics that we’re actually going to be analyzing and inspecting as we go throughout the course so it’s probably the most important table you need to know then we have four related tables or commonly known as dimensional tables these things have descriptive attributes that we can use in our analysis so for things like store we relate it using the store key and the sales and then stores table and the store database has information on well the stores similarly been said about the product and also the customer table the date table is slightly different in that it relates to the different dates specifically our order and delivery date the last table in this is that currency exchange table and it’s not related at all to our fact table and we’ll show why in a little bit now you may be wondering how can you actually go through and see what this database looks like and understand what are the tables in it well we’re going to be exploring tools later in the course specifically this is pg admin right here where i can visualize that erd and it shows how our fact table of that sales table is related to all those other different dimensional tables additionally it’s pretty nice because i have this kazo 100k and i can go into something like schemas and then down to tables and further i can further explore all these other different tables as well even looking at things like the columns for the sales table but we’re getting ahead of oursel we’ll learn how to do that in a bit i’ll teach you some shortcuts on how you can actually do something similar to this in collab so let’s get into running some queries first thing we need to do is go through and actually run all the different cells in your notebook basically get that database loaded into our environment and so we’re looking to explore what are the tables in this database that we just loaded into here i’m going to use gemini for this if it’s your first time using this ai model from google it’s going to prompt you with this privacy notice make sure you click continue and i can prompt it this of what sql query shows the tables in a database what we can do is access all these different table names by looking in information schema which is a meta database and specifically using the data attribute the looking at the tables within it which is a table now for this you can either click copy cell or you can do add code cell now remember we’re going to have all the syntax highlighting issues because we’re not or we don’t have in that magic command we need to put at the top specifically that percent sql so i’ll just copy that from here paste it up here and then run this bad boy so from this we confirm we do have six tables in our database and if i wanted to i can convert this data frame to an interactive table like this and then we also have this option to visualize it which we’ll be doing down later down the road so let’s explore first that sales table as that’s the most important part of this whole puzzle i want to see all the different columns of this so i’m going to use select and then star we’re going to do this from that sales table now if you’re noticing right now i have some autocomp completion happening right now you see i typed sales and i have this underscore fact underneath it this is the ai autocomp completion especially whenever i’m learning how to use sql i don’t find this very helpful and actually quite distracting so we can turn this off real quick if we go into open settings and select under ai assistance we can uncheck this option here for show ai powered inline completions whenever we close this we can see no longer pops up now this is good enough query as is but anytime i do a select star type thing it’s very resource inensive especially if there’s a lot of columns and rows so with this i’m going to limit this to just the first 10 rows then from there press control enter also don’t need this query off to the side so i’m going to close that so with this sales table we can see that it has all those different relations to those other tables such as the dates customer key sore key and product key from there we have information on what is actually sold in this sale specifically the quantity the price the cost and then also the currency used and its exchange rate in our example at the end of this we’ll go through calculating what is the net revenue and how we need to actually multiply or use all this together to calculate that let’s get through exploring these tables specifically we’re going to go with the easiest one first next of exchange rate if you recall our currency exchange table is in no rel way related to that sales fact table but what the heck is in it well exploring it we can actually see that in it it has a date column from currency to currency and exchange rate basically it at a specific time in history it tells you how you could convert a currency from one to another what the rate you need to use that now conveniently our sales table automatically just includes this exchange rate which was calculated from this table so technically this table is only needed if you need to go back and dive into understanding the exchange rate and how it’s trending over time all right we have four tables left and they’re all the dimensional tables that related to our sales table let’s start with store first this one is related to that sales table on a store key and then has information on where this is located such as country name of the store even the size next up is our product information and it’s related to that sales table on that product key it has information on the product specifically what is the name who’s the manufacturer how much it even weighs and what categories and subcategories it falls into next up is our customer table it’s related to that sales table on our customer key and this has a bunch of information related to the customer itself like where they’re located what their name is what their birthday is blah blah blah anyway what you notice right here in the middle is we have these ellipses and that’s because there were so many columns in this it didn’t show it here now previously whenever we were looking for the tables in the database we could run this on that metadata inside the information schema so what i’m going to do is actually i’m going to take this right here command c this and i’m going to paste it right into here but for this we don’t want to use tables we want to use columns running shift enter on this this only gives us table name information so i’m actually going to change this to select star run shift enter so we can see everything available in this query and inside of here i can see of this columns table we have a table name and column name so what i can do is i can now filter this for the table of customers so i’ll specify where table name is equal to customers running this again pressing control enter got a typo it’s customer running control enter again so now i have a way to view all the different column names and it’s not cut off and so we can see everything inside of it but not really finding anything that great right here for now but other stuff we’ll use in the future last table to explore is that date table this is related using that date column here to the sales table order date and delivery date now this table has a lot of different ways that you could aggregate all the different date data in here by looking at maybe day of week or month or year so this is great and all especially if you’re using a tool like powerbi and you want to just grab something quickly in order to filter maybe for january 2015 data but in this course we’re going to be diving deeper into using different date functions and so we’re not really going to rely on this table at all to get the data out because you won’t always have a date table available in order to investigate things so basically just ignore this bad boy now let’s wrap this lesson up by getting into an investigation of how we can use all these tables together for a common example so let’s say my boss who’s not so good at sql comes to me and wants to get some different revenue data that has information about customers and also products they’re ping purchasing and whether they’re of different high value or low value items so we’re going to walk through this example calculating the net revenue for this and how we can put this all together using all the different tables first thing we need to do is calculate net revenue so let’s look back at that sales table we’re going to use that same query as below and we get this table that we saw previously now for this how do we want to actually calculate that net revenue well in order to do this we need to use the net price now you’ll notice from this the net price is less than the unit price that’s because the net price is the price after all the different discounts promotions or any adjustments so basically it’s what we actually charge to the customer when they pay for the product and with this net price we need to multiply it times that quantity so what i’m going to do is put a comma here go to a next line and say we want to multiply the quantity times the net price and we’ll say this we’ll label this as the net revenue now when i name variables or when i name new column names i’m going to put this underscore between it i just find it easier to read the naming convention that kazo’s database is using and looks like i have a typo which is pretty good that we hit this right now because this is how i’m actually going to go through and troubleshoot this first it will tell me that there’s this runtime error anytime i’m running a query you can just ignore that you’re going to be seeing that all the time but it actually points this carrot here to where the issue is specifically it’s point to this line and it has to deal with quantity is not spelled correctly at all running this again pressing controll enter okay we actually have it now and over to the side we have that net revenue double checking this it looks like all the numbers are actually getting calculated correctly there’s one last step to do and that is we need to convert it to a common currency right now you can see that they’re using pounds here and then us dollars below basically we’re going to use it all the same i’m in america so we’re going to be using us dollars all we have to do for this is just multiply by the exchange rate gone ahead and added it in and now we can see that it is in fact adjusted for what it needs to be now we’re going to be adding customer and also product information using this customer key and product key but this table’s already getting sort of large so i want to condense it down to different columns i’m for sure i’m going to use and really the only other thing i care about is order date so we’ll go ahead and simplify this table down to this next we’ll move into our second of five steps and we want to filter for our recent sales specifically we want things from 2020 and greater for this i’m going to use a wear clause and i want this for that order date that we have in that sales table to be greater than or equal to january 1st 2020 now let’s go ahead and try to run this and it looks like it works now i would say in order to be safe if you’re ever working with date data that you’re not sure if it was converted to the date type specifically in postgress you can use this colon operator and then specify the data type you want to use for this in this case date so order date is getting converted or cast as a date this is going to work just the fine but just a tip for you all right next thing my boss wants added in is the customer info about who ordered that order now in order to do this we need to use a join and there’s four major types of joins left join right join inner join and then full outer join in our case we want to perform a left join because table a is our sales table and we want any related data to that a table in the sales table returned from that b table or customer table so let’s add this left join we’re just going to go between from and where i’ll add in a left join we want to do this on the customer table we’re going to give it the alias just c to make it easy similarly i want to give sales an alias as well i’m actually going to bring this down and then indent this over i’ll give this the alias of s now for this left join we want to do this on from the sales table we want to use that customer key and then from the customer table we want to use customer key so we’re going to use good actual naming conventions here i’m going to add that s dot to the front of order date along with the front to quantity net price and exchange rate now i’m going to go ahead and run this to see if it actually works and it looks like it works we don’t have anything from the customer table i’m going to go ahead and add in all the different columns by doing basically a c.ar notation to bring all those in all right so from this list i can see there’s a few different columns we want that my boss has told me about specifically we want to get the given name or first name surname country full and then also the continent that they’re from all right second to last step we need to add that product information in and similarly we’re going to be forming a left join with this we’ll give that product table an alias of p and we’ll be connecting it on the product key of the sales table and the product table once again i want to see everything from that product table so i’ll do p.star running this control enter i can see that we connected it properly with all the different product information once again i don’t want all the different columns associated with this only want to select few does my boss specifically these four columns of product key product name category name and subcategory name all right so looking pretty good with this only one last step to do and we’ll have all the information we need specifically we want to look at whether a customer is high value or low value looking at the net revenue we want to basically bin these customers into whether they’re spending less than $1,000 or greater greater than $1,000 in order to accomplish this we need to use a case when statement and we’re going to add it in at that last column right here so we’ll say case when we want to look at the net revenue but we can’t use an alias inside of the select statement because it’s not necessarily defined yet so we just need to take all of this below paste it in here and say greater than 1,000 and in that case we want to say that it is high else we want to say that it’s low so we can end this and then we’re going to use the alias for this of high low real original i know let’s run this pressing control enter inspecting it we can see that our formula is working for those values that are greater than a th00and we’re marking it as high so this has everything that we need in it for my boss remember right now we’re doing this limit 10 we actually need all the different data in it so i’ll go ahead and press play looks like we have 124,000 different rows in this and if i want to export this to my boss i could click this here in order to convert this into this type of table but what’s really convenient about this is i can now copy this entire table which allows us to either export to a csv json or even markdown csv is most common so i’ll use that all right so now that’s our initial dive into this kazo data set we now have some practice problems for you to go through and get even more familiar with this data set working through some problems in the next lesson or the next chapter we’re going to be diving into using the case statement in order to pivot data super exciting all right with that see you in the next chapter welcome to this chapter on pivoting with case statements and specifically we’re going to be using statements like case when and aggregation in order to pivot data but what the heck is pivoting data let’s take a look at this simple example focusing on that first table first typically our data comes in a long format and in this case we have an example of a columns of date category and sales where we have different categories of a and b it’s very common to pivot things such as on the category here of a and b so that way we get to more of a wider format as shown below this is not only easier to read and understand and analyze but also easier to visualize which we’ll be doing in this so what will we be covering in the lessons in this chapter in this lesson we’re going to be focusing on understanding the basics of using aggregation methods such as count and sum in order to pivot data we’ll use count to analyze the number of customers per region and then we’ll use sum to calculate the net revenue based on different categories in different years in lesson two we’re going to build this up further and start looking at statistical functions such as min max median and average for this we’ll get into an example of calculating what is the median sales across categories then finally in lesson three we’re going to jump into advanced use cases of case statements specifically we’re going to be looking at things like segmentation we’ll learn how to analyze by multiple and conditions in order to look at things like bucketing for certain years based on revenue and then similarly we’ll use multiple when conditions in order to analyze different bucketing of revenue tiers and see how they apply across different categories now i just showed a bunch of visuals and the goal of this course is not learning how to build or make visuals which i will show in this but really i want to be able to show that hey with these insights that we’re gaining you can take it a step further and visualize it all right with that let’s get into it in this first example we’re going to do a review understanding count but also distinct count in order to calculate the total number of customers per day in 2023 this will be the final table that we end up getting as always if you want to follow along open up that blank sql notebook and run all the cells in it so we can get started so remember we want the total number of customers per order date we can uniquely identify this based on the customer key so add a select statement from there i’ll add order date followed by customer key and then we’ll get this from that sales table let’s start with this first so as we can see from this we have this is the first of 2015 we have duplicate customer keys but then we also have a bunch of different ones we’re going to start simple first we’re just going to do a count of all the customer keys so i’ll wrap customer key and count and provide it the alias as total customers let’s run this and this isn’t going to work right because well we need a group by right so adding that group by statement we’ll add in we want to do this by that order date and then run this again all right so now we have the order date by total customers right now i’m noticing that the dates are not in order so i’ll add in an order by order date and not too bad but remember previously whenever we were actually looking at it we could see that customer key is actually duplicated we want to find the unique customer so we want to use something like distinct so going back up into our original query all i’m going to do is add in distinct in here and then run control enter and now those numbers are going to drop right because they have a we’re going to remove all those duplicates last thing we need to do for this one is just add a wear condition for filtering for dates in 2023 so i’ll add an order date and for this i recommend using the keyword between so we don’t have to do that greater than less than all that kind of mess and then putting in between january 1st 2023 to december 31st 2023 running this we can actually check the contents yep january 1st to december 31st one quick note now on visualizing this you can use this button right here and actually select it to go through and draft different visualizations to try to understand what is going on here with the data what it will do is it will give you different previews in our case this is time series data so i know that’s the best choice to use for the visualization whenever i go to select it it will autogenerate all the different python code you need in order to visualize that data and then all you have to do is click add cell and then running this you can actually visualize it in more detail right below so that’s why i really like collab for this is because it has gemini implemented into it makes it super simple for you to just go forward and actually visualize this all right let’s now get into actually pivoting using count as an aggregation and for this we’re going to be looking at something similar from that last example understanding how many daily customers we have but broken down by region specifically three continents of europe north america and australia for this we’re going to be getting this final table where we have things like order date in the leftmost column and then we have the customers based on the different regions in their own individual column first things first though what continents do we actually have available inside of our database it’s underneath the customer table when we run this we can see as a previous report in got europe north america and australia so let’s go forward with actually adding this table into the query that we just made at that last example in order to do that we’re going to be performing very commonly a left join and that’ll be with the customer table with an alias of c and we’ll do this on our customer key and what we’ll need to do now cuz we have two tables in here we’ll need to assign an alias also to our sales table and then also to all those other different columns that come from the sales table running this to make sure that the error there’s no errors there are accidentally messed up order date run this again okay everything’s working fine now but now we need to create individual columns for total customers based on continent so how are we going to do this well let’s focus on this syntax right here we’re going to be using the count distinct that we use as we used previously and inside of this we’re going to be throwing in a case when statement it’s case when a condition then what the output we want it to be the column in this case and then end and then finally assigned an alias so i’m going to go ahead and copy this right here and i’m going to insert it in the next line underneath here but we need to go through and actually fill it out so the condition is we’re looking for if it equals a certain continent so for the continent from that customer table we’re going to see in this case if it equals to europe and specifically the column that we want from this is then that customer key so i’ll go ahead and put that in and this one will give the alias in this case called eu customers let’s try this bad boy out and bam now we have our european customers in here let’s go ahead and add the other two as well of north america and australia all right i got those in as well have the north america and then also the australian customers go ahead and run this and scrolling down we can see that based on the total customers the europe north america and australian they do add up to this line right here so that field of total customers is now somewhat redundant i’m going to go ahead and actually remove that and this will be our final query now visualizing this one similar to the last one this one i find especially has multiple different columns in it the visualizations it provide aren’t that good specifically it is here in these time series but it’s broken up to where this one’s europe this one’s north america and then this one’s australia they’re not all on the same graph so unfortunately gemini in this case is not that strong in producing graphs if you really want to visualize it and you want to know my method for it all you have to do is go ahead and click that table and then remember you can actually copy it and this is going to copy the table to your clipboard so this contents right here i want it as a csv i’ll go ahead and copy it and we’ll need to put it into some sort of document because it’s pretty long so you want to put into a document such as csv so on mac i’ll put in something like textit um on windows you’ll put into something like notepad i’ll just paste the contents in using commandv and then from there just save it inside your favorite chatbot in my case i really like chat gbt you could use gemini claude whatever i’ll give it the simple prompt with the actual document of visualize this as a line chart and then with it visualized we can actually i like going in this interact mode on chatgpt we can actually go through and you can see both the all three of these regions along with visualize if you want to download the graph you can just click it there last example for this lesson for this one we’re going to be looking at using the sum function with case when in order to look at what is the total revenue by category and we’re going to be using that case when in order to look at 2022 verse 2023 this is the final table that we’ll be creating where we have category in the leftmost column and then we’ll have the total net revenue for 2022 and then for 2023 right next to it now for this i don’t want to start from scratch so i’m going to do take this last query that we took right here and then paste into cell make sure it runs properly all right now for this i want to just start simple i want to first look at what is the total revenue by order date so i’ll just start by first removing we’re going to be done in 2022 and 2023 removing this wear clause also we don’t need this customer table so i’ll remove this as well along with these this count distinct that we did for all the different customers with it just simply like this i’ll just start run it and make sure yep everything’s appearing it’s got all the different order dates in it okay now let’s get the total revenue and that’s going to be done by using sum now if you remember from a couple of lessons ago you need three things for this quantity net price and then also exchange rate so i’ll add all three of them here using multiplication and i’ll assign this as the alias of net revenue um remember anytime we’re doing an aggregation need to have that group by let’s go ahead and run this not bad but right now we’re aggregating it by order date and we actually want to break this down based on the category just as a refresher you don’t need to run this query what we need is from the product table is right here this category name so one we’re going to need to merge this with our sales table and two extract out that category name so inside of our original query we’re going to go ahead and do a left join connecting in the product table with the aliasp and on specifically that product key we’ll go ahead and run this to make sure that it still executing properly okay good we didn’t bring anything from the product table in we need to do that now and what we want to do is replace this order date now but with category name and we have it in three places so i’m going to show you a shortcut real quick so what i’m going to do is i’m going to highlight all of this right now you can see it’s only selected on the top one i’m going to press on mac command shift l on windows you’d press control shift l and now all of these are when i press backspace all of them are removed and then as i type all of them get typed in super convenient saves a lot of time and then i’ll go ahead and run this again by pressing controll enter and bam now we have category name and net revenue for each we have this net revenue across the entire data set still need to filter down but this is pretty good so far now in order to do this bas it up on 2022 and 2023 we need to be using a similar type syntax that we used before specifically wrapped in our sum function we’ll use our case when when it meets a certain condition of 2022 2023 we’ll provide it the net revenue when it meets that condition else if it’s not that year it’s going to be zero so whenever we sum it all up you only sum up if it’s that year and then finally we’ll end it with an alias so i’m going to go ahead and just copy this all and then inside of here i’m going to paste it down below so our first condition is checking on whether the date is in 2022 so for this we’re going to be using that order date column and we want to check if it’s between a certain date specifically between january 1st 2022 to december 31st 2022 had a brain fart there for the column for this we’re going to be using what’s above here inside of our net revenue of all three of these columns multiplied together and then finally the alias we’ll provide it we’ll call it total net revenue 2022 let’s go ahead and run this and bam we have it for 2022 this is looking good let’s go ahead and put a comma on the end and i’m going to go ahead and copy this and then pasting it right below then i’ll just need to go through and update it to make sure that we’re now using instead of 2022 that we’re actually using 2023 make sure to also change the alias okay running this processing control enter we get almost our final results once again we don’t need that net revenue in there it’s not telling us what we need so we’ll go ahead and remove it and now we have our final table and from this we can see that for some strange reason from 2022 to 23 for all of these columns all the data went down that’s not really good i’ll leave that to my boss to figure out all right it’s your turn now to go through we have some practice problems aligned for this to get you more familiar with how you can use case when statements in order to pivot data using these different types of aggregation methods in the next lesson we’ll be building on this focusing on statistical functions such as min max average and median and diving further into revenue with that see you in the next one now that we’re warmed up using basic functions to analyze pivoted data we’re going to now shift our focus in using statistical functions for this specifically we’re going to be covering these functions we’re going to warm up by focusing on the easy ones first of average min and max in order to pivot that database and understand some data insights and then from there use the percentile count or continuous function in order to analyze the median revenue of sales and we’ll continue on that same trend of analyzing this based on all these different categories to see what is the highest performing category so where can we find out what statistical functions are available to us well we go to the source documentation here at postgress they have the section on all the aggregate functions which includes the statistical functions and scrolling on down we can see max and min which we’re going to be using shortly which find the maximum or minimum value of expressions across all non-null input values and then similarly we have a whole host of in-depth uh statistical functions those around correlation looking at r squar standard deviation and even variance so let’s get into actually analyzing using min max and also average i need you to start up a blank notebook for you to work with and so what are we going to be analyzing for this well if you remember back from last lesson we calculated the total net revenue by category broken down for 2022 and 2022 we’re going to be doing a very similar approach to keep it simple looking at things like min max and average because of this if you still have that query you can go ahead and just copy that query right above as we’re going to be reusing that and modifying that to apply these new functions so inside my blank notebook i’m going to go ahead and paste that right here and actually running it press control enter first one we’re going to try is average and this finds the arithmetic mean of all non-null input values so pretty simple in here we’re going to keep this query mostly all the same but instead of doing sums here we’re going to be performing the actual averages because of that i need to name the aliases appropriately naming them average net revenue 2023 i’ll press controll enter go ahead and run this and bam now we have our average values and this is pretty neat because if we remember back computers had the highest total revenue but yet in this home appliances have the highest average net revenue anyway if you want to visualize this we could click that graph thing and try to actually visualize it below but being that this is categorical data i don’t find that the graphs that ever provides are that good because this table is so small i actually sometimes can just take this and copy the entire contents and just paste it right inside the chat itself since it doesn’t take up too much space and give it the prompt to visualize this and then bam we can see the different average values for these different categories across the years and actually compare them seeing things like computers actually were lower in 2022 than 2023 now that we understand average let’s explore min and max and it’s going to be a very similar syntax to this so i’m going to use some ai to automate this i’m going to go ahead and just copy this query right here open up gemini and i give it the prompt add in min and max statements similar as done with these average statements and then below this just go ahead and paste it in let’s see if it can actually do this going to expand this out to actually be able to inspect this and it looks like we got it done so we don’t need to be all repetitive anytime there’s repetitive task and give to ai to actually do this i’m going go ahead and actually insert this into here and close out of gemini and then i have all of these syntax errors because remember we don’t have the magic command for sql at the front and now i can go ahead and actually run this pressing control enter and bam now in one table we have not the average the min and also the max all formatted and typed out correctly pretty neat with ai so let’s crank this up a notch and start looking at a similar analysis but now using the median for those that are not familiar with what a median is if you were to have a list of numbers and then you were to sort them in order the median is the middle number so in this case when we have these seven numbers right here six is the middle number whereas when we have eight numbers we take the average between the fourth and fifth number which could be only four and five and that becomes 4.5 now median is extremely important especially when you’re working with data in this case we’re looking at salary distribution this from my python course and we’re looking at salary distributions and you can see that we have the salary go up and then go down but then it goes out and we have like high out values way out past 350,000 if we just use the average this average is going to be pushed towards a higher number and is not going to be representistic of the actual data so median helps fix this issue by basically sorting all those numbers taking that middle number and getting a more representistic number of what you would expect to see in this case salary what would you expect to see i wouldn’t want to expect to see a higher salary when i know i’m going to get a lower so you may be like “this is pretty easy all i got to do is change all these average values to median and then run this unfortunately there’s no such function as median hence the no function matches this given name and argument type and that’s common across all databases whether you’re using postgress sql server or mysql we’re going to use this percentile con or continuous and that continuous portion is a key part because now this function that we’re using percentile cont is not only an aggregate function but it’s an ordered set aggregate function so what does this all mean not only do we have to use percentile con and what fraction we want to use for this in this case the median or half of it is 0.5 but we also have to use this other syntax here of within group and then order by so let’s actually break this syntax down using this percentile continuous function we need to provide it basically a list of ordered values it’s not going to sort it itself and be able to pick it out like other aggregate functions because of this we first in parentheses have this order by column this specifies how we want to order the values that we’re going to be picking out the median value from but this only sorts the values we actually need to bind it to this percentile continuous function that’s why we have this within group portion right here to bind that ordered set if you will to that function so let’s just take a simple example first using net price here i have a simple select statement of net price we’re taking it from sales itself and it looks like we have almost 200,000 rolls of net price let’s get the median value from this so i’ll first start by using that percentile continuous function notice they also have a percentile discretet that’s if you don’t want it to average if you have two numbers in the middle you don’t want it to average if you want to actually pick a certain value you use discretet i mostly stick to continuous and then we’re finding the median value or that that is at the 50th percentile hence 050 and we need to first bind what we’re going to be binding this so we’ll use that within group and then in parenthesis we’ll use that order buy specifically of that net price and then we’ll assign an alien an alien an alias of median price let’s go ahead and run this bad boy and bam we get that median price of $191 just out of curiosity i’m going to compare it to that average net price and similar to what we saw with that salary data that i was showing previously the average price is much higher and that’s because we have these high value items that aren’t necessarily purchased as much driving that average up so media in this case is a lot better at getting a representistic understanding of what the common net price is people are seeing so what are we going to be calculating this last example well we want to find out what are the median sales by category comparing 2022 to 2023 notice here we’re going to say sales i’m going to use sales more frequently um but this is technically net revenue but in the business side we typically just say this is sales i don’t like to start from scratch from this so i’m going to work with that very last query that we just did where we found out the average min and max four different categories so i’m going to go ahead and just copy this all and then paste it into a new code cell here remember we’re not going to be using this average min or max so i’m going to go ahead and remove it let’s just start by getting the median net revenue or sales for basically all the years and then we’ll filter down by 2022 and 2023 after so i’ll define that we want the median by specifying percentile continuous we’ll use the binding function within group and then we’ll use that order by and this will be done on the net revenue which is quantity times net price times that exchange rate we’ll give it the alias as median sales all right let’s see if this bad boy works controll enter all right not bad we have our median sales for our columns but fast forwarding to the future remember we want to call them on 2022 and 2023 so starting with 2022 first i’ll put year 2022 here so know that that’s what we’re working with basically we want to provide the necessary values right here inside the parenthesis to filter down for 2022 so because of that we need to use a case when statement so i’ll add in case and then from there i’ll press enter and indent this in and then we need to fill in when the column name equals a condition then we basically we want this value of the net revenue and so after that we’ll actually end it okay so we need to fill in this column name equals condition mainly we want to meet the condition of verifying the order date is in 2022 so we’ll remove this out and we’ll start by defining the order date we’ll use that between argument and specifying that we want between january 1st 2022 to january or december 31st then it’s equal to these values i’m going to go ahead and just for good measure to make sure it’s a little bit more readable put that into parenthesis so just to be clear right you can see this order by we have this pink parenthesis right here it’s then doing a case statement to determine if they’re within a certain date then it’s equal to this value else not going to have any values let’s go ahead and run this all right not too bad i want to add in 2023 now i don’t feel like retyping all the values so i’m going to use gemini for this and i’ll paste in the code giving the prompt of addin 2023 also under this thing and it looks like it did it correctly i’ll go ahead and insert this in double checking it yeah looking good and now running this final query we have the median sales for 2022 and 2023 so just taking it a step further actually analyzing this we can see that comparing those median sales to that total net revenue which is also total sales we can see some interesting insights specifically for computers from 2022 to 2023 the median sale actually went down and corresponding with this the total sales of that same category of computers went down so maybe it’s something you could bring up to the svp of computers all right so you now have some practice problems to go through and get even more familiar with using these statistical functions when applied with pivoting and using case when statements in the next lesson we’re going to be getting into advanced segmentation we’re going to be learning how to use keywords like and and when to break down analysis even further with that i’ll see you in the next one welcome to this last lesson on using case statements in order to pivot data and in this lesson we’re going to be going into advanced segmentation so what is segmentation well it’s a really important data analytics concept in order for you to take large data sets and break it down into smaller pieces in order to analyze different behaviors as a data analyst i’m applying this concept all the time when i’m using large data sets so i can dive deeper into the details and understand different behaviors so how are we going to do this well we’re going to start off easy in our first one we’re going to learn how to use the and statement within a case when statement in order to analyze multiple conditions for that net revenue of all those eight categories we’re going to break it down looking at segmentation of year based on 2022 or 2023 along with looking at whether it has a high or low value median price mainly look at the net revenue for orders that are less than the median value and look at the net revenue for those greater than the median value for a second and also final example we’re going to be looking at how we can use multiple when clauses within a single case block this is particularly important whenever you need different outcomes based on different conditions and for the example we’ll be doing we’ll be breaking down the revenue into multiple different tiers so instead of looking at orders less than and greater than the median value with this we’re going to take it a step further and we’re going to be able to look at orders based on where they fall in certain percentiles now before we get into both those examples i want to just demonstrate it real quick how to actually use both of these concepts the first concept is we could use and to combine multiple conditions within a case when statement and this is simply just done by adding condition one and condition two and use that and end statement so for this one we’re going to be looking at two things quantity and net price i’m going to go ahead and run this query right here we can see based on our order date we can see things like the quantity and then also the net price what we want to do is create a new column and classify whether these orders are a high value order so basically i have a quantity greater than or equal to two and the net price is greater than or equal to maybe $50 and then if it’s not that we just want to call it a standard order so going to insert a new line underneath this select statement starting with our case statement and then indent it in to insert in when we’re going to be checking two things right we’re looking at what is the quantity and that it’s greater than or equal to two and adding in the and keyword we’re going to look at the net price and whether that one is greater than or equal to 50 in this multiple condition case we want to categorize this as a high value order else we want to categorize this as a standard order we’ll end this case statement and give it the alias of order type okay running this pressing controll enter we can now see that this allows us to do multiple conditions and those that have greater than one or greater than 50 are categorized as high-v value orders the second concept to understand is we can use multiple when clauses within a single case block now there’s no limit to the number of wens we can put into here but basically it’s shown as every time you have a when you then need to have that then keyword and specifying what you want after that and then usually end it with some sort of else now i find myself using this type of approach of multiple when statements whenever i have to break it up into different categories for example we’re going to be following the same approach right looking at quantity and net price but we’re going to want to categorize this now so previously we were just categorizing high-v value orders those greater than two and greater than 50 and everything else is a standard order instead we want to more precisely fine-tune this we want to classify when it’s a multiple high-v value item so greater than two and we’re going to change the value to greater than 100 then we want to also check for single high-value items so those that are greater than 100 but are a quantity less than two so one and then we’ll categorize those that are multiple standard items so those that are greater than two but still less than 100 and then everything else is going to be a single standard item so we can build on this query that we already used previously one thing to note is like i said we changed this so this is no longer 50 i’m going to change that to 100 and call this multiple highv value order for this we just enter a new line enter in our when statement and then use what we’re going to analyze for is the net price greater than or equal to 100 then in that case we’re calling it a single high-v value item next when quantity is greater than or equal to two then we’ll have multiple standard items and then finally the else will be a single standard item okay let’s go ahead and run this bad boy and scrolling on down we can see that it appropriately classified based on these multiple different conditions pretty neat all right so if there’s anything you get out of this video it’s these two concepts because we’re now about to get into more technical examples to demonstrate how you would use this in the real world so as always i like to start out with what we’re going aiming to achieve in this and similarly we’re going to continue our analysis looking at our categories but for this we want to not only break it down by year looking at revenue in 2022 versus 2023 but the reason why we need this and condition is we want to segment it further in order to understand the low revenue and high revenue what do i mean by that in the last lesson we looked at what was the median order value for a single order well basically we want to see what is the total or net revenue for orders less than median and then what are those greater than median thus high now technically as we showed in the last lesson we have median values for each of the different categories in order to understand how this and condition works in here we’re going to keep it really simple at first and we’re just going to calculate a single median value for all the categories and apply it to all so let’s start by calculating that median value we’ll start with select and then use that percentile continuous function and then use within group as our bridge to then put in order by for calculation of our net revenue of quantity net price and exchange rate we’ll name this as the median for right now we need this from the sales table and since we’re working between 2022 and 2023 we’ll add a wear clause on this as well specify and use an order date between 2022 and 2023 and i have a syntax error because i applied an alias of s for sales we’ll be using this later so we’ll keep it i’ll add that s there run this again and we get a median value of 398 so remember what do we want to do we want to calculate basically the revenue that is less than the median value and the revenue that is higher than the median value so just as a reminder we’re trying to calculate with that median value of 398 for orders that are less than 398 what is that total revenue low revenue and then also the higher what is higher and doing this for 2022 and 2023 so what i’m going to do is go back to the problem that we used previously because we reuse this where we’re calculating those median sales um at the end of lesson two in the last lesson i’m going to go ahead and copy this and then back in our blank notebook underneath our median calculation i’m going to go ahead and paste this in now we’re not going to be using these median sales like we calculated it right here so let’s just run this to see what we have right now and it should just show all eight of our categories now we can add in those calculations so specifically for this one i don’t care about the 2022 and 2023 23 i just want to calculate the low net revenue and the high net revenue we’ll start with low first we know we’re going to be adding everything up so we’re going to be using the sum function for this and then we’re going to have a case when condition and it’s going to have that syntax of case when the condition then the value and then end it and we’ll end it with the alias of low net revenue so the condition is we want it to be less than that 398 that that order value is so we’ll add in quantity time net price times exchange rate and make sure that it is less than 398 this line’s getting a little long so i’ll go ahead and bump this on down and then also indent it in and now we need what is the value well the value is what is that revenue so i’ll copy the same formula that we used above command c and place this into value one so let’s go see if this works right now as written and looks like it does do these numbers make sense yeah they do so now let’s add a statement for the high net revenue i’ll go ahead and copy this all add a comma and then paste it into here changing this to greater than equal to 398 and then changing this to high and then going ahead and run this make sure we have no errors looks like we have everything here so now we’ve at least gotten that low net revenue and that high net revenue the next thing we need to do is now actually segment it down based on 2022 and then 203 and this is where we’re finally actually getting into what we’re trying to teach with this concept of using an and in a case when condition specifically inside of our case when we can use two different conditions using that and keyword so basically we want to add our multiple conditions right here inside of here before the then so what i’m going to do is enter down and then indent in and start that second and condition so we’ve already checked for the first condition of hey is it less than the median value the next thing we need to look at is the order date between january 1st 2022 and december 31st 2022 and i can actually go ahead and copy this and also place it in this condition as well i’ll then update this to be this is 2022 and this is also 2022 let’s run this make sure that it’s working properly and i got a little bit of a typo i added two betweens in here i don’t know what i’m thinking there try it again okay now it’s working all right this is looking pretty good now all we got to do is add in 2023 so i’ll use gemini for this cuz i don’t really want to fix all that code paste in the formula giving you the prompt of add in two columns for 2023 it generated it so i’ll add that code cell in and then from there add in that uh sql magic command run this pressing controll enter and bam now we have that net revenue for 2022 and 2023 whether low or high so that’s how you use the and condition but i’m going to be honest this query i don’t like hard coding in values like this and so i’m going to show you real quick a little advanced technique so that way you don’t have to hardcode values in so if we scroll back up to our original query right here that actually calculates our median value we can use a cte to insert in this value into that query now as a refresher for cte they start with that width command and then from there you’re going to be assigning the name of that cte so i’ll name this one median value and use as from there i’ll put an opening and closing parenthesis along with actually pasting in that value i like to indent it in to just make it easier to read we’re not using it yet but i’m just going to press control enter to make sure that my query is still operating correctly it is and then now all i need to do is insert it into this from command right here so i inserted it in as median value giving it the alias of mv and then if we remember the column name is median so i’m going to replace that 398 remember we can press command shift l to select all of it and then type in mv.median okay let’s run this bad boy hope it works and it does gets our final value now this is pretty good now that we can see these breakdowns between the years based on high and low net revenue we visualize this we can actually understand better what happened with the computer sector specifically remember computers drop down in revenue well it’s not for those low revenue or those value of orders less than the median value really what happened was is they saw a drop in the orders for those high value orders those that are greater than the median so pretty interesting insight that we found out and we actually break it down further in the next example in this example we’re going to be building on that last example further by using multiple when clauses within a case block previously we were only using one when clause but we’re going to actually step it up a notch and use two when clauses why is this important well this is going to allow us to segment within a column into in our case different revenue tiers so all of these will be categorized whether high low or medium along with the associated calculating for the total revenue so what does this high low and medium revenue even mean we’re going to be segmenting based on where an order falls within its percentile specifically if an order’s revenue is less than the 25th percentile we’ll cate categorize this as low between 25 and 75 is medium and greater than 75 is high now why this 25th and 75th percentile well it’s actually pretty common in statistics to use these values in order to bucket things into their different quartiles technically statisticians like to call that range between 25 and 75 the entire quartile range we’re just going to call it medium and then everything less than this low and everything higher than this high so that’s the basis on where we’re getting these numbers for now you may be like luke how the heck do i calculate the 25th and 75th percentile but remember the median is the 50th percentile so that’s why in this case we use that 0.5 so let’s go ahead and copy this that we used before and i’ll put in here.25 and we’ll call this that 25th percentile going ahead and running this we get an error because silly me can’t start an alias with a number in sql we actually need to use a letter to start so i’ll just say hey this is revenue 25th percentile and now run this okay not bad let’s do this for the 75th percentile and adding all in pressing control enter we have the 25th percentile and 75th 75th should be much greater than the 25th as expected looking good all right we’re going to be using these values in our final query so we’re going to be not going to be hard coding them in so i’m going to create another cte so i’ll go ahead and tab this over and then from there create a ct of percentiles and then assigning it inside parenthesis here so running this make sure it works just fine not going to cuz i need to insert a query below it i don’t want to start from scratch with that bottom query so i’m going to actually just going to scroll up to that previous one that we just created i’m going to copy this one and we’ll modify this one to make sure that it works pasting it in here first thing i’m going to just get rid of all of these conditions that we created along with that median value because we’re no longer using it but i will go ahead and add in that cte of percentiles and we’ll just name it something like percentile okay let’s actually try to run this and i can see what the error is now i have this comma after the end before the from let’s try this again okay we got all the categories as expected and we have our cte inside of there so the first thing i think the easiest is because we already have this group by and everything like that let’s add an aggregation in here to actually provide what is that total revenue so we use the sum function for this then we’ll add in the quantity time net price time exchange rate and we’ll give this the alias total revenue all right let’s go ahead and now run this all right so we have our categories and total revenues we now need to do one more step and this is actually what we’re trying to learn of implementing specifically breaking down all these different categories into those revenue tiers and so for this we’re going to be using the multiple when statements within our case i’m going to go ahead and copy this right here and then paste it in between here all right so the first thing that we want to check for is whether we’re mean that low tier condition basically that the order revenue is less than that 25 percentile so for the condition we’re checking whether this value here i’m going to go ahead and copy this and paste it in here is less than or equal to that revenue 25th percentile that we’re calculating up here so we brought it in with that alias of pctl and that’s that revenue 25th percentile and we’re going to assign it the value of low for the next condition i’m going to go ahead and just copy this right here paste it into condition two and i’m going to just say we want to check to make sure that it’s greater than or equal to the 75th percentile in that case it’s going to be high everything else is going to be classified as medium for the alias for this we’ll name it as revenue tier all right looks like everything’s in order let’s go ahead and run this bad boy press a control enter and we get an error which i’m catching it because it’s pointing out that it’s with the when clause right here now we’re aggregating right we’re doing the the sum of the total revenue based on these different tiers so technically we also need to do a group by for this so underneath here i’ll add in revenue tier sher run this again and bam now we got it not too bad now technically i would like in the order i’m a little nitpicky i would like the order low medium high so i’m going put number values out in the front of these in order for it to be able to actually order in the correct order so i need to actually add that in underneath the category name and we’re going to do an revenue tier run control enter we got a comma run control enter okay now we have it and better order high medium low 1 2 3 and this is pretty neat cuz we’re able to do multiple segmentation in order to analyze these different revenue tiers and we actually visualize it when we put into something like a 100% stacked column chart we can see that we have the high the light blue whereas medium and low are getting darker something like that computer sector that we keep on talking about they are very reliant on their revenue coming from those high ticket items those that are greater than 75th percentile whereas something like games and toys are highly reliant on low and medium value items so pretty interesting insight one last technical note for both the first and last problem we used these 25th and 75th percentile across the entire range of categories and similarly for that first problem we use the median value across all the different categories technically this isn’t necessarily the best practice you should do for this we went back to that first problem you’d actually want to calculate the median for each of these different categories and then from there actually segment it down and break it down further but whenever we look at the query it breaks down it gets a lot more complex and isn’t really what the focus is of this lesson focusing on that adding multiple when conditions or using that and condition but if you like to see the nitty-gritty technical details they are in the notes all right you now have some practice problems for you to go through and get more familiar with using these multiple different conditions for segmentation with that we’ll be moving into the next chapter on dates and we’re doing a lot of different functions with that with that see you in the next one welcome to this chapter on date calculations and in this we’re going to be learning how to use different date and also time functions and keywords in order to analyze data now the first lesson we’re going to get an intro and how this is useful in performing time series analysis specifically we’re going to use things like date truncate and two character in order to calculate things like the number of unique customers or net revenue per month in the second lesson we’re going to fine-tune how we can extract out certain components of the date and also use things like the current date or now in order to investigate certain time periods from when we’re analyzing it and in the final lesson we’ll cap it off with keywords like interval and functions like age in order to calculate things like average processing time and compare that to the number of orders we have and this is all very important and so kelly and i included this in these beginning chapters because you’re going to see as you go throughout the rest of the chapters a lot of the concepts were learning with how to manipulate dates are going to be used in those future chapters date and time data is everywhere you go you can’t get away from it now i highly encourage you for any of these functions or operators if you’re curious of learning more go into the source documentation which provide the link over here or maybe over here so we’re going to be using the date trunk function so what does this do well in date trunk you provided a field that you want output from it whether something like seconds minutes hours days weeks whatnot and you provide the source usually this is in the form of a date or time so let’s go over a simple example first i’m open up with a blank notebook here i just have a simple query where we’re looking at the order date because that’s what we’re going to be manipulating with this date trunk formula from sales and we only have 10 uh outputs so i’ll controll enter okay this is good now all these dates are the same um but i want to be able to see all the different dates so a little trick you can do is i’m going to use order by and then use the function random now whenever i run this pressing control enter i’m getting random dates right here so we can better see if it’s actually applying to a lot of different data anyway let’s get into that date trunk function so typing this function right here we can see that it also outputs in here hey we first need our date expression and then we need our date part which i just clicked to open up we can also use this documentation to further investigate what is going on here so pretty convenient of what’s going on here okay so we’re going to first input in that date expression and it’s a string so it needs to be in single quotes i’m going to put in month from there we need to put in the date part so i’ll put in order date now we’ll run this pressing controll enter and we get if we see these these order dates we can see that it’s just the month now notice the data type of this it’s getting converted to a timestamp and this is a little bit inconvenient and a little bit too verbose for me so we can clean this up specifically if you remember from a few lessons ago we can use this double colon sign which is the cast operator and we can cast this instead of as a timestamp as a date running control enter now i just have it output as a date take it one step further and also just rename this as order month and we’re good to go all right so what are we actually trying to calculate in this exercise this is the final table that we’re aiming to get to in it we have the order month which just showed you how we did and we want to get with this we’re going to use group by to analyze the net revenue and also the total unique customers so let’s start with that query that we just previously built we’re going to add onto this by first calculating the net revenue remember we use the sum function for this this is calculated by multiplying quantity times net price times exchange rate and this is our net revenue so i want to make sure that this is operating correctly and silly me we’re doing an aggregation of sum so we need to perform some sort of group by so instead of this order by i’ll put in a group by and specifically we’ll call out that we want to do it by the order month i’ll also go ahead and just remove out that order date so we don’t have to add it to that group by run control enter okay not bad getting net revenue per order month we only have 10 results right here i have it to limit 10 mainly i do that when building queries so they operate more quickly i’ll take it off at the end next thing to get is total unique customers so i’m going to go ahead and add that in we need to do a distinct count of the customer keys so count and then distinct specifying customer key and then we’ll assign the alias of total unique customers running this okay we got totally unique customers net revenue and order month so exactly what we needed out of this we can go ahead now remove that limit 10 and press ctrl enter bam now date trunk is really great especially if you just want to specify one attribute you want to extract out of it such as something like month as we did you could either do quarter year decade century or even millennium and so if i like to customize it more i like to use the two character function specifically you provide it something like a timestamp and then the text output and it outputs it in that text format scrolling on down we can see that it has a host of different options that we can use for this you can specify a lot of things like hour of the day year even things like month and the good thing about this is you can actually combine these together in a format or in an order that you want so let’s just show this simply by implementing in order date and formatting them as month and year we go ahead and press control enter and we have our random dates right here let’s now add this new function in in its own line so enter two car and then the next thing is the actual field itself and then next is what we want to output so in the case that we want something like just the year only i’m going to put it in single quotes and then go ahead and run it and we can see unlike the last one where we had to like cast it as a date and remove all the time and stuff it just outputs what we need and then if i wanted something else say not only the year but also the month i could just put it in there so double m in that case running control enter now we have the month and year so this table is super helpful in understanding what are the different formatting options that you have for this what you can use so back to the original example that we were working with we can actually replace this entire line and use this two character function specifying order date and then how we wanted it formatted and of course we’ll give it that alias similarly of order month so it’s performing the group by properly i’ll press control enter and so let me forgot a comma after this and so now i feel this output is a lot more readable regarding this order month because that removes that day and we can actually see what it is for each of these months the revenue and total customers now we because we aggregated this on a monthly basis vice that daily basis that we were previously doing we removed a lot of noise and from this we can see that in 2020 we had obviously some sort of worldwide event that caused an impact in the number of unique customers and also net revenue that we had but it looks like as of 2022 these numbers have returned back to normal except a slight dip in 2023 maybe something we’ll have to investigate later all right it’s your turn now to go and test these out we have a few short practice problems for you get more familiar with this in the next lesson we’re going to be jumping into even more complex formulas such as current date or even now with that see you there in this lesson we’re going to build further than we learned in the last lesson specifically by understanding more about how we can actually filter dates and even do it dynamically first we’re going to learn two more functions on how to format different dates and for this we’re going to be diving into how we can analyze things like the net revenue for each year for every category and then from there we’ll use things like current date and now to basically filter data by a certain time time frame from this time period now pretty neat all right first of the two functions is date part and this one extracts a specific component from a date or time stamp as we can see we have date part function unit and then what is the source or column name host of different options so with the sample query we can look at things like the year month or date here we’re using that date part function specifying those different components the applicable column and we give it appropriate aliases one thing to note with this which is not necessarily my most favorite part is that they come in with precision so they have decimals after it and i don’t necessarily want this depending on what unit i’m working with because of that i prefer to use something like extract and it has a very similar format to date part it’s actually based on date part and we can see as going through this we can do things like day decade dow and whatnot basically all the same things that we can use in date part we can use in extract the syntax for this is slightly different though in this case we’re going to use the unit and instead of doing a string for it we actually do an uppercase actual variable name and then we say from the source in our case our column name so this bottom query is using that extract and we’re going to do exactly the same thing that we did just above in that similar example using date part we specify year month day from order date and provided the appropriate alias for it let’s go ahead and run this bad boy and like i mentioned i like this one a lot better especially when dealing with things like year months or dates where i want in your digits for these values so let’s use this extract function in order to analyze the net revenue per order month now previously right we use this two car or two character function to actually analyze per order month what the net revenue is let’s instead create columns for months and then also for years so i’m going to go ahead and remove this portion right here and put in extract it gives us a hint up here we want to put in the part first well we want the year next we’re going to use the keyword of from and then the date expression specifically we want to use order date we’ll give it the alias of order year next we’ll get into adding that month one we’ll write the extract formula do it for month from and specify order date for this we’ll give it the alias of order month now the group by for this we’re doing two columns now so i’m going to want to actually do order year and order month this looks good let’s go ahead and run it and not bad it’s all over the place so i’m actually going to go ahead and change this to do an order by at the end of this so that we can get some semblance out of this data and bam this looks a lot better and now we have this in different columns so depending on how those that i give this data to they can slice and dice it even more easily all right let’s actually get into some new concepts and implement dynamic filtering by using things like the current date or the time now in order to filter back let’s talk about current date first so typing a simple select statement along with current date it provides me the documentation for this and it basically says hey it returns the current date as of the specified or default time zone parentheses are optional when called with no arguments basically you can provide a time zone if you want anyway running this we can see we get the current date i’m filming this apparently i’m filming this on valentine’s day that reminds me i need to call my fiance and actually wish her happy valentine’s day so i’m glad i saw that anyway that’s current date let’s go to the next one and that one is using the function of now similarly i can run a select statement with this just calling the function make sure you do have an open and closing parenthesis and we run this and we can see that it is valentine’s day at 2:30 in the morning okay actually not filming this at 2:30 in the morning this is actually green witch meime which is over in england so that’s what time it is there so that’s why for the current date it gives you the option to actually throw in a time zone in there to update it appropriately so what are we going to be calculating well the short answer is we’re going to be looking at understanding what is the net revenue per category for those orders 5 years ago back from today we’re basically building this table the important thing to understand is this this is a dynamic filter and these type of things are very important and understanding to do because sometimes you want to or you’ll have workflows set up that run queries automatically at midnight and you don’t want to be pulling in all the data maybe you only want the data for the last 5 years and things like this are great for that so let’s start with a base query that we’ve seen time and time again first we’re going to be extracting out the order date the category name and then perform a calculation for net revenue we’re going to be doing this from the sales table and left joining it with the product table on the product key and then because we’re doing aggregation above for the net revenue we need to actually group it by the order date and the category name pressing control enter we got this and it looks like these dates are unordered so i’m going to go ahead and throw in an order by run this and now we have the order the dates in order so we only need one do one more step but i’m going to break this step down because we want to include only orders within the last 5 years basically we shouldn’t be seeing anything from 2015 i’m in 202024 as of filming this so we’re going to create a wear filter in here to do this but i want to break it down slowly to show what’s going on step by step so i’m going to insert in how what components we’re going to use to filter within a wear clause we’ll start simple first we’ll look at current date and see what it outputs to here as expected we get to see it’s valentine’s day now in order to extract out these last five years we need to get what is the year in the current date and also what is the year in the order date so for this we’re going to use that extract command we want from it the part which is the year and we’ll do from we’ll keep it simple first with just the order date i’ll give it the alias of order year running this see it’s working just fine we’re getting that order year for all those different order dates next let’s extract out the year from the current date so we’ll just put in here that keyword of current date and we’ll say this the alias of current year run this okay not bad now we want the year that we’re going to be filtering by right we want it to be basically 5 years ago so all we need to do is i’m going to copy this one we’re going to be getting rid of all these um but i want this one right here and instead what we’re going to do is we’re going to do minus5 and we’ll set this one as minus5 clever i know running control enter we can see that the minus5 is actually five behind this so what we need to do in our wear clause is combine these in a way to where it filters for that so wear clauses go underneath from or the left join and for this we want to make sure we want to see the order year so i’m going to go ahead and copy this above c is greater than or equal to this minus5 value that we did right here and i’ll go ahead and post that in here let’s go ahead and run this crl enter and bam now this is a little bit hard to read but we can see just looking at the order date column these are the orders for the last five years i’m going to go ahead and remove these unnecessary values now we don’t need this anymore that was just for building this and we can see that we have this now this query’s built for the last 5 years now you may be like “luke this is it’s valentine’s day right now but this is going back to january 1st 2020 what if we went to be very precise about that?” and i’ll say “aha to that we’ll answer in the next lesson.” all right you now have some practice problems to go through and get more familiar with using these different things and creating your own dynamic filters in the next lesson we’re going to get into date differences basically using functions like age to measure the time between different dates with that see you in the next one in this third and final lesson on this chapter on date and time function objects we’re going to be going into now understanding how to calculate intervals in the first half we’re going to continue on from that problem from the last lesson and instead of making really that verbose way of calculating the last 5 years we’re going to use the keyword of interval to write much more succinct queries and readable queries to understand what we want to get an interval of in the second half we’re going to be going into a pretty interesting business problem of exploring average processing time so in order to calculate this interval between the order date and also delivery date which we know we’re going to use functions like age and also show what can be done with that previous function of extract first let’s explore how to use this keyword of interval interval can represent a span of time such as days months hours minutes decades or even weeks and we use this by using the interval keyword and then a value and unit so let’s test this bad boy out i’m going to run a sele simple select statement specify the keyword of interval and then let’s do something like five centuries with this we can see that it gets the title of interval and it calculates it to be 182,500 days anyway normal output for this is in days whether you’re using centuries or even use something like months running control enter comes out in days so how can we use this in the query that we used in the last lesson to filter for orders within the last 5 years i’ve simplified the query basically we’re pulling out the current date order date from that sales table and we use this formula of pulling the year out from order date and the year out from the current date and subtracting five run this we can see that the current date is valentine’s day and the order date is within that last 5 years now notice this right i called it out last time this goes all the way back from january 1st 2020 so technically this is slightly greater than 5 years so let’s write this query a lot more succinctly i’m going to go ahead and remove this portion right here and for this we want to make sure that the order date that we’re actually trying to filter for is greater than or equal to dates of 5 years ago so we can use once again that current date and we can subtract from it the interval of 5 years running this bad boy we can see that this one now does the last 5 years as shown by the order date and it’s very specific right it gets all the way down to filtering it to february 14th valentine’s day in 2020 so getting into cleaning up that full query from last time this is actually it right here if we run it again we can see that it does the current date the order date category name and net revenue so it breaks down by category the different net revenues this one technically remember wasn’t 5 years so what we can do is go back and replace this portion right here with that newly formated clause that we came up with and then whenever we go ahead and run it we can see that now we have it for the last 5 years all right before we get into age and also review of that extract function let’s look at what we’re actually trying to solve in this portion of the lesson if you recall back we have two columns an order date and delivery date column i forgot to put a comma here so it’s not appearing now it is um so we have things like order date and delivery date what we can do with this type of information is calculate how long what is like an average processing time for a customer to receive an order it’s a very important metric whenever used in business analytics so what we’re going to do by the end of this is show on a yearly basis not only the net net revenue which is those blue bars but also what is the average processing time for those years and we find that it’s going up so what are we using for this well we’re using the age function and with this we provide two in this case timestamps we provide dates and it’ll output an interval let’s do a simple example first running it just right inside of a select statement we’re going to be using the age function and then we’re going to provide it two dates now i have a couple of errors with this i’ll go ahead and run this first pressing control enter and we have this render age and it says hey no function matches the given name and argument specifically it says age integer integer i don’t want to evaluate integer i want to evaluate as a date the problem is with the date we have to provide it as a string so make sure you have single quotes around it running controll enter we have it now if you notice from this i did the 8th of january to the 14th of january and it’s saying it’s -6 dates for the age function to get a positive value you need to provide the end date and then you need to provide the start date so i’m going to go ahead and place these in the correct order running this get six days now let’s say we want to do some math with this i have currently six days and let’s say we wanted to subtract i don’t know five days from this if i put in here after this minus five and try to run this i’m going to get an error specifically it’s going to have that the operator does not exist interval minus integer right now this is an interval and we’re trying to subtract an integer we need to convert this portion to an interval sorry i mean integer need more coffee well we can use the extract function i’m going to go ahead and remove this all cutting it out we’re going to use the extract and we need the part and then specify the from keyword and then the date expression for this we’re going to specify day it doesn’t need to be in single quotes for this it understands that keyword of day i’m specify from and then for the date expression i’m going to go ahead and paste in that age now running this pressing controll enter we can say see that we get that six from this and i can do the minus five from this now pressing control enter we get one so let’s get into calculating the average processing time by year and we’re going to be doing this for the last 5 years similar to this table we also need to calculate the net revenue but we’re not going to do that until the very end because it’s going to make our query a lot longer with actually joining in the table that has the revenue data so let’s start simple first and let’s just look at the order date and delivery date and we’re going to be getting this from the sales table now let’s put in a new column in for the processing time we’ll throw that age function and remember we need to put the end date first so that would be the delivery date followed by the start time or the order date and we’ll name this as processing time this query is getting quite long so i’m going to go ahead and throw in a limit of 10 in here just to start with running this we can see we’re getting basically zero processing time everything’s getting delivered on the same day that it’s ordered i want to see a little bit more different orders so i’m going to throw in an order by random and run this and now we can get some actually that have some days in there to show that okay this is actually working so let’s start getting the average processing time and aggregating it based on year because of this we need the year for this i’m going to use the date part function and as the first argument we need to specify what is we actually want we want year and we want that out of we’re going to go with the order date of when it actually started we’ll give this the alias of order year now next thing we do is actually get into aggregating this age but remember we have this processing time is an interval of of the data type interval so 3 days 0 days it’s not going to be able to actually average that so we need to use that extract function first and i need to specify the part from this specifically it’s the days and specify that from keyword and then age delivery date and order date i’ll then put a closing parenthesis on this and then rename this alias to average processing time now we’re doing an aggregation so one we’re going to need to specify a group by and then because of this we don’t need to have that order date and delivery date because we have to aggregate by that and so i’ll remove this order by random and we’ll throw in a group by right here specifying order year also this won’t have a lot of outputs i’m going to remove that limit statement then running this and silly me i’m reading this here the delivery date must appear in a group by clause or be used in aggregate function basically i forgot to use the actual function right here oopsies throwing that in of average and now running this we are getting the average processing times all right we need to clean this up still these years are out of order and these amount of digits on here are just unreadable so i’m going to throw in an order by clause underneath here and we’re going to order by the order year running this we now have it in order and now let’s clean up this average processing time i only really want two digits and if you remember from the basics course we went over the round function in there and with the round function you provide the value or column x and then after that n is the number of actual digits that you want or decimal places after this so if you don’t use anything with zero digits but we want two so we’ll go ahead and put two on there run control enter bam got average processing time over well we want to do the last 5 years so from our previous example up above i don’t like typing code if i don’t have to i’m going to go ahead and copy that wear clause and then putting it underneath the from statement now running this we have for the last years the average processing time all right now just one last thing to do we need to now add in that revenue based on each of those years for this we’re going to be using the sum function to sum it all up and we’re going to be multiplying quantity time net price times exchange rate and we’ll give it the alias of net revenue all right let’s go ahead and run this not too bad typically with these high of numbers i don’t care about these two decimal places so i’m going to use the round function again and in this case i’m not going to specify an argument at all run this and okay it looks like it’s given it two decimal places with just 0 0 what if i can just specify this and looks like i can’t specify zero but instead what i can do is i could give it something like cast and then for cast i can specify that i want to cast it as an integer we’re going to control enter bam now we have what i want and then if we graph this we can see that the average processing time over time has gone up from around a little less than one up to 1.6 even with the dip in revenue or i think the number of orders probably loosely correlated we still saw the average processing time go up so this is a good little data point to keep track of and we can pass on all right it’s your turn to go through you have some practice problems to get more familiar with the extract age and also interval keywords and functions and from there we’re going to be going into the next chapter after that on window functions pretty complex topics i’m looking forward to get into it see you there all right welcome to this chapter on window functions this is probably the most requested topic for me to cover in this intermediate course so i was super excited to get into this now we’re going to break this chapter up into five lessons starting with this lesson focusing on the syntax of window functions doing some simple examples and explain it to you then we’ll start picking up the pace looking at things like aggregation ranking lag lead and then finally we’ll close it off looking into how we can use things like frame clauses well this doesn’t matter unless you really understand what window functions are so let’s look at a simple example so let’s look at a query that’s breaking down the net revenue by an order number in it i’m listing things like the customer key and then the order key and then the associated line number for that order calculating the net net revenue and then getting it from sales we’re then ordering it by the customer key so what’s going on here okay customer key 15 made only one purchase of over $2,000 but customer 180 did three separate purchases where two of these purchases of were the same order they just have different line items so now let’s say based on all these individual orders we wanted to find out because we want to do some deeper analysis what is just the average order specifically what is the average net revenue for an order what i could do is run an aggregation function removing all those other different columns and just run it here and see that the average order order value is 1,000 but i want it in this table and i can’t get that necessarily unless i actually get it in this type of format using this aggregation but this is where window functions come in instead all i have to do is just insert in our window function don’t worry we’ll go about it over in a second it’s using the over function in this case go ahead and run it and have an error because i got a comma in here and we can see that it’s the same value as below of 132 but it’s now in our original table just like we want it so we can do even more calculations with it so why use window functions they let you perform calculations across a set of tables related to the current row like we just showed and like we showed they don’t group the results into a single output row this is very beneficial as we’re going to demonstrate some future exercises so this is using it for things like running totals ranks or even averages anyway let’s get into the syntax for this we start by defining the window function or what we want to do if it’s an aggregation something like sum or count if it’s ranking it’s something like rank or dense rank the next is over and this defines the window for the function inside of it we have the keyword of partition by we’ll get that in a second let’s actually go back so let’s walk through that window function that we just saw without using partition by and i’m going to create a new line and for this the window function we’re going to use for this is average because we’re calculating what is the average net revenue from there i’ll put our variables in there of quantity net price and exchange rate then we’ll put over and it’s very important after this that we include open and closing parenthesis even if we’re not going to put anything in there and then i’m going to give it a very verbose title to make sure we understand what it means the average net revenue of all orders going ahead and running this we can saw similar to before it’s at 1,032 but now let’s say we wanted to filter this type of window function further maybe by something like the customer key and this is where partition by comes into effect it divides the results into partitions or better said divides it into separate groups without actually having to use such as a group by clause to do this so going back to our previous example i’m going to go ahead and copy this all so we can see it add a comma new line and paste it in and this one we’re going to find partition by customer key and we’ll say that this the average net revenue of this customer let’s go ahead and run it and scrolling down we can see for customer 15 it only had one order so that’s the average net revenue whereas customer 180 had multiple and the average of that was 836 so let’s just briefly explore the power of window functions by looking at a simple example i’m not going to ask you to follow or understand the syntax because we’re going to get to it later on but this is going to demonstrate the features that we’re going to be getting to in this chapter so here we are looking at things like customer key order date and net revenue i’m going to go ahead and run this so let’s say for each of these customers we wanted to rank their orders from highest to lowest based on net revenue well i could use something like this window function that’s using row number and some other stuff that we’re going to get to and in this case we can see that it actually calculates the rank for this specifically it has the highest at rank number one and the lowest at three for 180 now let’s take it to another level we could do something like calculate the customer’s running total so in this one we can see with 180 that has multiple orders first it’s at 525 and then it jumps up to 2500 these orders on the same day so the running total is the same we could also do things like get the customer total net revenue and this one isn’t really that impressive because yeah we could see that it gets the total but personally i like it because i can then use this to maybe calculate hey what percent is this order of the total net revenue of a customer in that case i can just add it in doing the net revenue divided by the window function to figure this out and so now i can the table by the way and now i can see what is the percent of the revenue for a customer so this makes even more unique of why window functions are so powerful so let’s actually get into applying those concepts so you can actually write those queries like i just ran through what we’re going to be finding is the percent daily revenue based on an order line item to do this we already know how to do net revenue we’ll need a window function to calculate daily net revenue and then we’ll calculate a percentage from that so let’s start building this query out we’ll list the order date the order key the line number which an order or an order key could have multiple different shipments with it so therefore it has different line numbers and then finally we’ll just start with the net revenue we’ll get this from the sales table and we’re just going to limit it to the first 10 all right so and as mentioned the line number right it just says 0 1 2 3 the highest number in this is six i don’t really like that these are two separate columns so i’m actually going to combine it i’m going to take the order key and multiply it times 10 so basically adds a zero to the end and then from there add in that line number and then i’ll give it the alias of order line number we can see that what it looks like actually here it gets accomplishes what we want so i can go ahead and remove line order and order key so the first thing we want to calculate in our final table is that daily net revenue in order to do that we need to use the sum function on our net revenue and now we want to use over and then inside of over that partition by remember we want the daily net revenue so we’re going to be putting the partition by of order date and from there we get that daily net revenue now now we want to calculate finally the percent that an order line item is of the daily net revenue this one’s going to be pretty simple as it’s going to be a lot of different copy and paste so first i’ll drop in the net revenue i’m going to multiply it times 100 so it gives us a bigger digit for that percentage and then from there we’re going to divide by all of this window function right here which i’m going to copy and paste into here and we’ll give it the alias percent daily revenue not too bad it’s all over the place i want to actually see this ordered for this day to see what is the highest so i’m going to put in an order by specifying the order date and then the percent daily revenue but for this one i want it in descending order and bam we get this final table showing this percent daily revenue based on the order i went ahead and graphed it so we could compare the different order line items for that day and we could see that some of the orders i mean these are taking up of 20% up to 10% of the entire daily net revenue and conveniently up the top of the chart but the total daily net revenue so it’s pretty convenient for window functions that we can get all this type of data into a single table and it makes it a lot easier later on whenever we dive deeper into it and maybe visualize it one minor note on this query it is getting a little bit verbose in that a lot of this is repeating stuff that we could reuse and that could be done using something like a ct or subquery what i could do is actually just put it into its own subquery of the core items that we need from this so the order date order line item net revenue and daily net revenue and then from there put it into something like a subquery so i’m going to go ahead and tab this over and so that way we can do a select star from and then put this all within parenthesis and we’ll give this alias of revenue by day so it still has the same output in below but now instead of having to repeat all that different code here like i did to calculate the percentage i just come up here and then insert a new row specifying i want to do 100 times the net revenue divided by the daily net revenue and give it the alias of percent daily revenue now running this boom this has everything that we have or want out of it and in my mind it’s a slightly easier to read and to get through when sharing with others so let’s now get into performing a cohort analysis in this last example and cohort analysis is going to be done a lot throughout this project because it’s pretty popular in business analytics all right what the heck is this well a cohort is a group of people or items sharing a common characteristic and then the analysis of this examines the behaviors of this over time specifically the behaviors of that group being a personal item so what does this even look like well for this example right here this is what we’re going to be doing and analyzing or putting people into cohorts based on the year of their first purchase and then from there calculating what portion of the revenue they are contributing to the net revenue so down at the bottom is the purchase year and then over on the y axis the net revenue in 2015 where this is the data that starts it starts in 2015 everybody contributing this is from cohort 2015 so that’s all the net revenue then we get into 2016 we have their 2016 cohort along with it’s a small contribution from the 2015 cohort in 2016 we work our way all the way to 2019 and we can say see once again that the cohort of that year is the largest contributor whereas those from previous years are less of contributors now it’s important that you understand for this example that the cohort is based on the first year that you made a purchase so what are we aiming to get out of this well we want to have this final table where we have the cohort year or the year of their first purchase and then from there the purchase year or the apparent year of the net revenue with the total revenue for that cohort so we’re going to start simple first with our first query looking at using a window function to extract out the cohort year based on a customer so we’ll start with the select statement specifying the customer key we’ll also do order date so we can see what’s going on there and we’ll get this from the sales table we’re going to limit this to only 10 values also have a comma right here we don’t want that going to press control enter and bam okay so we’re getting customer keys and order dates i’m also going to go ahead and just for good measure i’m going to order by the customer key so that way we can make sure that we’re looking at this all appropriately specifically if there’s grouping such as here is 180 i see them all together so now let’s use a window function to get our cohort year we’re going to start first by just getting what is the minimum date out of or for a customer so in the case of this 180 i would expect it to be this order in july so we’ll start this window function using the minimum of specifically order date and we’re going over and then inside of parenthesis we want to put the partition by of the customer key and i know it said date right now but we’re going to just name this the alias cohort year because we know we’re going to change it okay press control enter okay looking at 180 it is in fact that lowest date for order date as the cohort year now what we want to do is extract out that year from there so i’m going to run that extract function on this and we need to specify the part first so that’s going to be year and then from and then everything after this is that date expression so then i’ll put a closing parenthesis all the way in the end run this one thing real quick i did show that how it was 2018 but now look at this if we go to something like customer key 387 we can see that their first purchase was in 2018 but then later on in 2023 they still have that cohort year of 2018 so we know our formula is working so let’s go ahead and clean this query up because i don’t need this order date at all for what we’re doing it for so i’m going run control enter now i’m noticing we have duplicates because customer key is appearing more than once so what i can do is add a distinct statement right after this and now when i do this boom i’m only getting distinct values for the customer keys and the cohort year so this table’s a lot more concise um we also don’t need this limit 10 anymore and technically we don’t need an order by either this is good start so we figured out that cohort year for the customer this is once again the final table we want to get to now what we need to do in order to basically add these additional two columns on of the purchase year and the net revenue is we need to calculate this if you will separately and join in that cohort year using something like a cte so let’s put this all into a cte that we can then join to that sales table to basically attach on for all these different customer keys their associated cohort year and then we can aggre aggregate and find out what is that total revenue so we’ll use the width keyword specifying this as the alias as yearly cohort we’ll use as and then an open parenthesis we’ll tab this on over and then put a closing parenthesis and then i just want to make sure that this works properly so i’m going to do a select star and do from that yearly cohort above and run this to make sure that it is outputting correctly yep still the same table okay now let’s join this on to our sales table for this is very important we get the correct join for this specifically we’re going to be connecting to the sales table so i’ll put that right here and then for a join we’re going to be doing a left join we’re doing a left join because we want to make sure that we have and keep all of the different sales values from it and then we’re joining using yearly cohort which has been distilled down to remove any duplicate data so we’re not creating duplicate rows for each of these i’m going to give them an alias this one s and this one y and then as far as how we’re going to join this you’ll be on the customer key from both of these tables let’s go ahead and well let’s actually do a limit 10 because there’s a lot of data all right so just inspecting the table we can see we have the customer key of 947009 and then it is joined on that customer key along with its associated cohort year so just as a reminder of what we need to get to now we need to get the cohort year and then the purchase year or the year of the order date and aggregate all this to calculate what is the net revenue now when we do this aggregation we’re not going to use a window function this time we’re going to use a group by on these different years so let’s clean up these columns that we’re actually using we’re going to use that cohort year and then also the purchase year which is based on order date so we need to extract out the year from order date and we’ll define this as the purchase year let’s just make sure this is correct before doing our aggregation next okay good we have all the order years and purchase years now we want to move into getting a sum of all the revenues so we’ll use the sum function specifying the quantity times the net price times the exchange rate and we’ll give this the alias of net revenue and so because of this i’m going to be doing a group by specifically on that cohort year and also the purchase year which we’ll need to put the function in here going ahead and running this we can see we have our results and anytime you’re finding your or getting to your final results you need to make sure that the numbers are making sense specifically i know that the net revenue for 2015 was around $7 million and i can see from this that for 15 i say 2017 mean 2015 so for 2015 is owned 7 million and this checks out also silly me i could also use purchase year in this case doesn’t necessarily have to be the function itself all right so we want all the values for this because we’re almost there i’m going to go ahead and remove that limit 10 go ahead and run this and bam we have our final values where it shows based on a purchase year how much a certain cohort contributed to the revenue for that year and this is the ultimate visualization that we get to and we can see that pretty interesting enough the cohorts from previous years don’t really contribute that much to the overall net revenue so we have a little bit of a retention issue all right it’s your turn now to go in and get more familiar with window functions by doing practice problems in the next lesson we’ll be diving we’ll be diving deeper into aggregate functions and basically fine-tuning our knowledge of how to use window functions with that i’ll see you there welcome to this lesson on aggregation functions using window functions anyway we last lesson we went through and started to apply aggregation techniques to window functions but we’re going to build slightly more further on this covering three key concepts so in the last lesson we actually used the min aggregation function to analyze the impact on yearly cohorts on the total revenue as we went through the years well in this one we’re going to do a simple analysis basically reinforcing what we learned with cohorts but this time using the count function in order to analyze the total number of unique customers and how they impact based on their cohort into future years next we’re going to move into using the average aggregation function and for this we’re going to be focusing on the long-term value of a customer basically using window functions in order to calculate what is the total amount of revenue that a customer has contributed and we’ll not only be able to break it down on a customer by customer basis but we’ll also be able to analyze it from a cohort year perspective as well and finally we’re going to wrap it up with some simple examples on understanding how to filter window functions basically where you should be applying your wear clause in order to filter a window function properly all right let’s get into it so for this example we’re going to be using count in order to aggregate our window function the syntax is all the same so major concepts remain all the same let’s get into what we’re going to be solving for this we’re trying to find out the number of unique customers which we’re going to use the customer key for this and find out based on their cohort or the first year they bought an order how they contribute to future years this graph right now is showing the total number of unique customers every single year and then from there broken down by cohort so we can see from 2019 we had those from 2015 16 17 so on for the final output we’re going to be doing it very similar to last time where we want a table of the cohort year and then the purchase year and then the number of customers or the number of unique customers based on a cohort year and purchase year now you could start with the query from last lesson and modify it to fit your need for this but i find this question is actually more simple than the last one so we’re going to start from scratch also it’s just good practice so for this we want to get not only the customer key but also based on a customer we want to get its cohort year or the first year it made an order and then also a purchase year when the year of a purchase was we’re going to be ultimately using that customer key to get the unique count anyway let’s start programming start with a select statement adding in our customer key next we want the cohort year so similar to the last time we first want to get that minimum order date for our window function and then from there we want to do it over the partition by customer key i’m going to name this alias right now cohort year cuz we’ll eventually get it into a year format right now it’s obviously just date for this we’re going to be getting this from our sales table let’s go ahead and run this just to see scrolling down to that 180 customer key we can see that it is all from june so this is looking good next thing we want to do is extract the year out of this so we’ll do an extract we need the part which is year and then from and then the date expression which we’re going to wrap all in parenthesis and then we’ll put another closing parenthesis on there to for the extract we’re control enter and we have the years now next let’s get the purchase year and we don’t need to do a windows function for this right we just need to extract the year from our order date so i’ll do an extract the part is year and then we’ll do a from and then the date expression is order date we’ll give this a name purchase year and go ahead and run it okay overall looking good everything look like it’s calculating correctly now what we need to do is move into actually getting the count of the unique customers using that customer key and you may falsely think that this is actually going to be wrong code right here but you may falsely think that you could use a group by to do this specifically we’d want to do something like count the different customer keys or i should say count the distinct customer keys and then from there add a group by to do by cohort year and purchase year however when we ever go to run this we get the following error message window functions are not allowed in a group by basically we can’t combine these window functions and group eyes so trying to use group eye in order to calculate this and save some code not going to work here just wanted to point that out but what we can do is make this into a cte and then use that cte to run a window function on to get the customer key so for this to create our cte i’ll give it the alias of yearly cohort open parenthesis and put all the syntax in there next just to make sure that everything is working correctly i’m just going to call a simple select star on from yearly cohort run this and it’s still running properly okay we’re good to go let’s refine this now now remember this is the final output that we want we want cohort year purchase year and then number of customers so let’s work to build this table for this i’ll remove the store put in cohort year first put in the purchase year and then next let’s build the window function to go through and count the unique customer keys but we don’t want it just on one thing we want it based on both the cohort year and the purchase year so in this case customer key 180 was a unique customer in 2018 which is also the cohort year but then as a cohort year 2018 was a unique customer and also two 2023 so for this we’ll first start by doing a count and one thing i’m not with this right this has some duplicate data we want to get unique customers so technically i’d only want to see for 180 this 2018 2018 but then also for this 180 this 2018 for the current year and 2023 i wouldn’t want to see duplicates so what i can do first is i can add a distinct up here onto this query running control enter and then it’s not really showing because we remove the customer key i’ll just put it in for the time being running this again we can now see that for customer key 180 now it’s just those two entries so for this we’re going to be doing a count of customer key or you can do countst star over and then this is when we would get into our window function using partition by both the purchase year and then also the cohort year and we’ll name this as num customers so let’s go ahead and run this all right not too bad the one thing to note right is this is has multiple different duplicate lines because we have all those customer keys in there so once again what we can do is we can just add a distinct right after the select statement so that way we can get it filtered down to only unique values and then from that we can see that okay this is all on order now so now we need to actually do an order by so we’ll add an order by doing by cohort year and then purchase year and scrolling down we have what we want now and i know based on previous calculations that we had in 2015 only 2825 unique customers so this validates or help understand that this data should be correct so if i were to visualize it this is what we get and it comes out very similar to our total net revenue so overall not a lot of unique insights that i found from doing this compared to net revenue but at least we explored it before moving on i want to touch on a short example specifically around what we talked about just recently on this error message that we got when we ran this query where it said window functions are not allowed in group eyes technically this isn’t entirely correct as i’m going to show in a second we’ll be able to run window functions with group eyes but overall i don’t recommend using window functions and group eyes within the same query and we won’t be doing it for the remain of the course so i want you to learn this major concept now so let’s look at this simple example we’re going through and we’re going to collect the customer key and then using a window function we want to count how many orders that a customer has and so we’re going to partition it by the customer key and this will be the total orders i’ll go ahead and just run this and so we can see that customer key 15 has one 180 has three orders so they have a total of three orders everything’s working fine but now let’s say we want to calculate the net revenue but this time we want to group this all up because i’m tired of all these separate rows and so we’re going to use a group by with this to find the net revenue so i’ll put in the average and this will be of the quantity time net price time exchange rate and i’ll give it that alias of net revenue we’re doing an aggregation so like usual got to use the group by and we’ll do this of the customer key now when we go to run this query it is going to work notice remember 180 is at total of three orders and i’m getting an error message because i’m silly and i didn’t put a comma after this column go ahead and run this now and magically this query does work now right because we have an eye with a windows function in it but now going to that customer 180 they only have a total of one orders in fact if you look at all of them and i can move into this bigger table all of the total orders for every single one of this column here is one so what’s going on here well what’s happening is window functions in the process of running through this run after a group eye so what’s happening is everything is getting grouped together and then the window function is running this causes a major issue of conflicting aggregations so if you’re not getting an error message stopping you from this you’re probably not going to get the right results there are better alternatives which we’re going to go over and mainly that’s using cte or sub queries and breaking up your queries to separate them with our previous query what happened was we ran our group by aggregation to find our net revenue it condensed all those customer keys down to one value and then secondly it finally ran that windows function so that’s why it feels there’s a one value for all these total orders cuz it only sees one after the group by so let’s fix this up so this actually works and see how we’re going to be doing this in this case i would want to run the ct first so i’m going to get rid of this aggregation of this average and we’ll give this the alias of order value also i’m going to be removing this group by because we’re not doing the aggregation anymore we’ll then put this all into a cte so there’s no aggregation inside of this one we’ll then just query this table getting the customer key and total orders to make sure that it’s aggregating properly i’m going to go ahead and press ctrl enter and with this one we can see that 180 has in fact three and now we can go through and actually do our aggregation with that cte specifically we would get the average order value and give the alias of net revenue and then perform a group by on customer key and total orders going ahead and run this bad boy we can see we have 180 with three orders and the correct value there so it’s working so for the remainder of the course you’re going to see me anytime i need to do a new group eye or a new window functions i’m going to just create a new ct and then do it there all right getting into that second exercise we’re going to be focusing on the average function and using this in our window functions overall the syntax is the same so nothing changes there but we’re going to introduce a new business concept specifically this one of customer lifetime value and as the name implies it’s the total revenue generated by a customer over their lifetime with that company we’re also going to explore some other concepts such as the average order value or the typical amount spent per transaction but that’s less of a focus for this more of ltv so for this the main concept of concern is lifetime value which we have the abbreviation of ltv and it is the total revenue generated by a customer for a business over their entire relationship with that company so what are we going to be ultimately calculating for this well we want to find out based on a customer so in this case the x-axis is that customer id we can see what their total lifetime value is and even compare it as with this dash line to the average lifetime value for that particular cohort that calculation is a little bit more tricky to get to but we’re going to get to it so the final table we’re aiming to get to is this based on a particular customer key we want to be able to extract out not only the cohort year but also the customer lifetime value and what is the average lifetime value of that cohort so we can compare that two now this type of analysis is really great because we could do something like target these high value ltv customers because they’re more likely to make purchases and that’s typically what businesses do they’re not going after the lower numbers they’re going after the higher numbers enough happen let’s actually get into it and for this first query we’re just going to focus on three things the first is getting that customer key the next is we want that cohort year which as we’ve seen before is extracting out using the year now there is an aggregation function in this of the minimum order date so we are going to need to do a group by after this but anyway next thing we want to get into is actual a sum of their total purchases so i’ll run a sum function put in the quantity times net price times exchange rate and then give this the alias of customer ltv specifically we’re summing up all of the revenue for that customer so it is that we’re going to take this all from the sales table and like i said we need to do a group by specifically by the customer key let’s go ahead and run this all right not too bad we have basically the first three columns of well the four that we need for this and speaking of that fourth column that’s what we want to get of the average customer lifetime value for a particular cohort but remember we learned previously can’t be inserting window functions in a group by so i need to put this all into a cte and then do the window function we’ll start with that width keyword giving the alias of yearly cohort then signing it this alias obviously putting it all within parenthesis like usual i want to double check my work so i’m going just do a select star from that yearly cohort and everything’s outputting like we saw previously good to go so far inside of our main query we want to one we want to have all the different columns so i’m going to do a select star it’s only three feel fine doing this but next is where we actually want to do that window function using average and for this we’re going to use that value of customer ltv over in parenthesis going to do a partition by and we want to do this by cohort year we’ll assign this the alias of average cohort ltv okay let’s go ahead and run this not too bad one thing is i probably want this ordered in a particular order specifically on the customer key and the cohort year so i’m going to stick an order by in there and specify cohort year and customer year and bam this is the final table that we need for this and this can tell us some different statistics that we can now use like i said we could send this off to maybe something like the sales department or marketing department and they could do targeted ads at these high-value customers in order to have a potential or more of an impact on revenue now i also graph the average lifetime value for each of the cohorts and as expected it does decrease over time that’s expected because they have less time in the cycle than say somebody that 2016 or 2017 guess the one thing to note is 2015 and 16 or less than 17 so the first few years we started off we didn’t do as well with customer retention and extracting value out of it so pretty neat insight out of this all right last part in this lesson and we’re going to focus on two examples very quick in how to use where within a query to filter properly and this is really important especially for the practice problems we have for this in order to understand that you’re filtering properly so let’s start easy first how can we filter before a window function well we could use this where statement here and it is going to apply before we actually invoke the window function itself let’s actually test this with a simple example so for this i’m querying to get the customer key and we’ve seen this windows function before of extracting the minimum year to get that cohort year based on that customer year i’m going to go ahead and run this and there’s trusty number 180 we see that it is in cohort year 2018 so we know the problem or the query worked out properly so let’s say we have a scenario where we only want to look at cohorts from 2020 onward basically we don’t want to put people in cohorts before 2020 we want to just analyze from 2020 onward this is a great example of filtering before a windows function in this case we can use the wearer and we’re going to specify that the order date is greater than or equal to january 1st 2020 now let’s see what happens with customer key 180 okay previously it was bucketed into as its first order in 2018 but now since we’re saying “hey don’t pay attention to that anymore i just want to focus from this point onward it getting reclassified as 2023.” so that’s how you filter before window functions the wear clause can be right there in the statement underneath the select and it’s going to get applied before the window function runs now contrast that with filtering after a window function in this case we need to do something like a ct or subquery we’re going to do a cte here we would need to get that cte and then from there filter so let’s continue on with this last example to show when we might want to use this so the first thing i’m going to do is i’m going to remove this where because we’re not going to do that anything with it we’re going to put this portion into a cte we’ll give it the alias of cohort and then i’ll do a opening and closing parenthesis to put it all within then we’ll do a select star and we’ll do this from cohort so now let’s insert our wearer and in this case right we want to filter after the windows functions specifically we want to remember previously customer 180 was in that 2018 time as its cohort year let’s say we just didn’t even want to look at any of the cohorts if they were broken into that cohort we don’t want to even classify them at all after 2020 so for this we want to specify where it’s greater than or equal to and the year in this case would be 2020 now what i would expect from this is that customer key once again is going to disappear also this from is messed up right here it’s not it’s from cohort okay let’s go ahead and run this and bam we notice now that 180 is removed from this because of how we actually applied this after the window function to remove those cohort years from the original purchases anyway wrapping your mind around how wear function are applied before or after window functions does require some practice so we got some practice problems for you go through and test out and get more familiar with it all right in the next lesson we’re going to be jumping into functions around ranking and that one is pretty exciting so we’ll see you in there all right we’re continuing on in this chapter of window functions now focusing on how we can rank different values and use a certain order to rank them for this we’re going to be covering three main types of ranking functions row number rank and also dense rank i’ll be explaining the difference between all these and we’ll be doing this by ranking customers based on how many orders they’ve completed so more as they completed higher the rank they are but before we even get into any of those functions we need to first understand how to use order by within a window function in order to get the correct ranking that we want now previously with sql you’ve seen order by used typically after the from statement to actually order your values but we can use it inside of the window function and what this can do is order our values within a specific partition that we’re running this window function on and order by as a reminder always defaults to ascending but you can specify descending so what are we going to do in well with the sales table you’ve already seen the customer key order dates net revenue what we can do is get a running order count and what this will do is based on an order so in this case for 180 it has it first order in june or sorry july so we have our first order and then in august on the same date we have two more orders so then it bumps up to three similarly for customer 387 they have four orders on their first day and then the next day or the next time they complete an order they bump it up to five so let’s build something similar i’m going to throw in a select statement along with customer key order date and then net revenue we’ve seen this all before this is going to be from our sales table i’m going to go ahead and run this just to see what it’s outputting okay sweet not bad let’s now just get with this a count of the orders based on using a window function based on that customer key so i’m going to insert a count function and we’ll just do it on count star we’re going to do this over and then i’m going to do a set of open parenthesis i’m actually going to indent this down to make this easier to read and for this we’re going to partition by customer key we’ll do by order by in a second i want to go ahead and actually see this first now we’ve seen this before but i want to call out some things specifically notice that the customer keys are different from before so it actually went through and ordered it with that partition by except it didn’t order it by or didn’t order the order date because this one for 180 in june or july is after the august anyway that’s something to note for later but we do find we get the correct calculations for this because 180 has three orders and we can see all of them here so now let’s insert in our order by i’ll put it right after the partition by and specifically we’re going to be doing it by that order date and this can control our row processing order let’s go ahead and run this bad boy and so inspecting this table we can see now that not only the customer keys in order the order dates in order and whenever we go through the count itself for 180 it has one and then the next time in august there’s two more so now it increases by three so our function’s working so for these aggregate functions like count average or whatnot it’s going to determine how values are accumulated row by row also i realize i never gave this an alias so i’m going call it running order count anyway let’s now use one more aggregate function to demonstrate this further specifically i want to do a running average of the net revenue so basically i after the first order i expect to be around 525 and then after these next two orders i’d expect it to be an average of all three of these and it’s going to do this line by line for this i’m going to insert a new line i’m actually going to just go ahead and copy a lot of this because the boiler plate code itself is going to be approximately the same instead of doing a count we want to do an average and specifically we want to do it on that net revenue so i’m going to copy that and then paste it into here we’re still going to be partitioning by the customer key and ordering it by the order date in order to carry carry out that rowbyrow execution and we’re going to name this running average revenue okay let’s go ahead and run this and now inspecting it we can see that yeah for the first one they only have one order next one of 180 the first order the average is in fact the same as it is but then when we move into the next round of orders it’s averaged among all three of these so for 180 at this point in their order history the average order revenue is around $836 with that knowledge let’s actually get into our ranking function specifically first we’re going to be focusing on row number and understand the importance of how it needs to interact with order by now in postgress they have quite a few different ranking window functions but in this lesson we’re going to be focusing on these top three right here row number rank and dense rank for row number this returns the number of the current row within its partition counting from one so for this let’s just label the rows in our sales table with a row number for this we’re going to select all the rows of the database and we’re going to say this is from the sales table since we’re doing all the rows i’m going to just limit this to the top 10 run control enter okay this is our values back let’s now get into using this to assign a row number at the front of here one quick note for this data frame that’s appearing here is this is the index right here but it’s not necessarily callable the 0 1 2 3 4 5 so we really can’t use that that’s why we actually have to generate this anyway after the star we’re going to start a new line cuz i want all the actual columns to or yeah all the different columns to appear for this we’re going to specify the row number and then run over and i’m just going to do an open and close parenthesis we’re not going to use uh a group by just yet i’m going to go ahead and run this and if we scroll all the way over we now have the row number right here 1 2 3 4 5 6 7 8 9 10 as expected and it looks like our data set is in order now i don’t really like where this row number is appearing i actually want it at the front of the data set and i’m also going to give it an alias of row num anyway let’s move it to the front so important thing to note is yes this does provide the row numbering but this actually does this in a well chaotic order and it’s not guaranteed that it is going to be assigned based on how the data set is in the system so i don’t recommend doing this i always recommend anytime you’re using any of these numbering functions to use an order by so what is this order going to be based on well every order has a unique order key and also line number additionally with this i’m going to also use that order date to make sure that we’re maintaining in that date order i’m not 100% sure if the order key may mix around in certain locations in time so for this i’m going to press enter and now i can enter in my order by and i’m just indenting this in to make it easier to read we’re doing an order by we’ll specify that order date first and we’ll just run it as is just to show this it’s still providing those row number in sequential order by order date but like i said we want to be very specific to make sure that it’s doing it correctly so what i’m going to do is also add in that order key and then that line number control enter and bam so this has what we need in regards to row number let’s now take this a step further combining it with partition by specifically let’s say that we want to start or have a number for like our daily order number and so every new day we want to start this over let’s look first what would it what is it at on the 2nd of january 2015 and we do this by inserting a where statement and this is saying hey filter this for where order date is greater than this this is only done just to look at that uh on the next day running controll enter and silly me already forgot what we learned in that filter lesson right whenever we’re doing the wear right here underneath the uh window function it actually will apply this filter data to there and so in this case it automatically did start uh numbering rig again at one but generally if i didn’t have that wear statement wouldn’t do it anyway not necessary for you to actually follow along and do this code i’m just doing this for demonstration purposes i put all of our original query inside of a cte called row numbering then i called it to look at the first 10 values in it anyway with this same queries below now i want to filter for the second basically where order date is greater than the first running this one we can see that that row numbering starts you know at 26 27 or whatever we want to do a new window function in order to assign a new numbering each day so let’s go back to that original query that we have remove that ct so we can make it easier actually to run through all this for this we now want to add a partition by right above the order by and for this we want that new numbering to start every single day so we’re going to give that the order date as the variable for this okay going to go ahead and run this and actually we’re not going to see any difference in what’s displayed here but we do see down here that in 420 that it only the numbers only go up to like 97 so it does look like it’s working what i’m going to do is i’m going to now just go ahead and copy this all paste that into that cte so we can demonstrate this again and then run this remember previously it was starting the numbering around number 24 or something but now on the second it is starting it at the first so this is working so let’s now get into comparing the three major types of function we uh using for this row number rank and dense rank note all of them provide big or an integer value from this they all have a different way of ranking depending on what your use case is so let’s look at a simple example for this so let’s say we went through and calculated how many o orders each customer did and this one up here they’ve had a total of 31 orders well we’re going to go through and rank them using row number and then rank and dense rank and then seeing how they actually differentiate from each other for this let’s first just pull in the information we need using a simple select statement we’re going to use customer key and then to count all the orders we’re just going to do a count star to basically count the line as an order and we’ll assign this as total orders we’ll get this from the sales table and we did an aggregation method so we’ll do need to do a group eye of the customer key so let’s go ahead and check this bad boy out and with this we can see the different customers and then the orders the or the total orders are all over the place they’re actually get where we need to order this but we’re going to be ordering it in our window function so i don’t want to necessarily do that until after our window function also this is just too many values i’m just going to do a limit 10 for the time being all right let’s get into now building our window function first with row number to assign a row number based on what are the total number of orders they have so for this i’ll start a new line we’ll insert our row number function we’ll do it over and then inside of here we don’t need to do a partition by because well we’ve already grouped by our customer key to find out what the totals are so all we need to do now is just put an order by in here specifically we want to order it by that count star and we’ll give this the alias of total orders row num real original i know all right let’s go ahead and run this all right bam what we have here is well not really what we want uh so these all have total orders of one and it is uh providing a total orders row number one two all the way to 10 but i actually want to be ranked from highest to lowest so as remember from the beginning we can actually insert in a descending comment right in that order by now when we run it we can see that we get this total orders row number and we’re starting at the highest of 31 all the way down notice with this when we get to numbers like 26 26 and 26 repeating it does assign a number of four five and six but technically these are all tied ranks and so that’s why we need to learn other functions like rank so i’m going to go ahead and we’re going to insert another line in here i’m going to copy this row number because a lot of this is just boilerplate that we can repeat instead of row number i’m going to change this to rank and then for this alias instead of row number num at the end and i’m going to add the i’m going to change this to rank running this now okay we got the total orders rank and if you notice from this one whenever we get here and we have repeating values of 26 this is going to assign at four four so if we actually see then when we get to 25 it assigns it the number seven so then we’ll skip five and six and now you’re probably like well loop what happens if i don’t want to skip five and six in my ranking method and i just want to continue on ordering from there well that’s where dense rank comes in so let’s once again going to go ahead and start a new line paste in our old code change this one to dense rank and then also update the alias to dense rank running this one i put a comma at the end of this don’t need to have it going to run again we now have this new one where okay we get here we have the repeating fours and then when we get to the next one it jumps or it stays uh consistent in number and jumps to five and then we have some uh similar numbers again of 24 and so these are all sixes so when i need to order something or number something it really depends on what is my criteria on whether i’m going to use something like row number rank or dense rank that’s why got some practice problems now for you to go through get more familiar with these functions in the next lesson we’re going to be getting into lag and lead which we’ve been doing functions that really look at only the current row it’s on but we can actually use functions that look either before or after certain rows pretty powerful all right with that i’ll see you in there all right welcome to this fourth of five lessons on window functions and in this one we’re going to be getting into functions like lag and lead these type of things in a window function allow us instead of looking at the current row to allow us to look at things like the row above it or the row below it so we’re going to be exploring these main functions and we’re going to be doing this first with a very simple example where we can go in and look at our 2023 monthly revenue and be able to evaluate our month overmonth growth because now we can look either before or after row and be able to calculate this from there we’re going to shift into our final scenario which is slightly more complex in order to analyze the growth of cohorts over the years and basically see how they change from year to year so what functions are we going to be exploring for this well there’s generally about five different ones that you can use let’s start with the easy ones first we have first value last value and nth value for first value it returns a value evaluated at the row that is the first window or first row of that window frame the last one does obviously the last one and then for nth value you can specify an an integer inside of there and it will return that row now for lag and lead they’re very similar in that this one you’re providing either a row that is lagging or a row that is leading but we’re already to get too deep into it we need to actually explore this with an example so what i want to do is first we need to calculate this we need to get in 2023 what is the monthly net revenue and then we’re going to be applying these functions in a window function in order to evaluate first last lag lead and try all these different ones out so let’s start simple with just building this query so i’ll start with the select statement and the first column we want is the monthly v variables so i’m going to use the two care function for this i really like the output of this it’s a lot easier we’re going to run this on the order date and i want it in this format we’ll give it the alias month next is we want the net revenue so we need to use the sum function for this as always it’s quantity time net price times exchange rate we’ll give it the alias net revenue we’re getting this all from the sales table and we’re doing an aggregation so we need to do a group by specifically we want to do the group by by month let’s go ahead and run this bad boy okay first thing i’m noticing is it’s returning it back but it’s ordered all over the place so i’m going insert an order by we’ll also do this by month and we want to analyze this for just 2023 so i’m going to insert in a wearer and we’ll just do an extract to extract out the year and analyze for 2023 so with extract we’ll specify the part from and then order date and we want this equal to 2023 it’s a digit so we don’t have to put that in a string and bam we have what we need now now we can actually start getting into running all these lag lead and stuff functions now because we’re going to be running window functions on this i’m going to put this all into a cte we’ll use the width statement we’ll give it the alias of monthly revenue and then i’ll provide some open and closing parenthesis and then i’ll do a select star from this cte and make sure it’s still outputs yep still good to go so let’s get into exploring these we’re going to start with the easy ones first like i said of first value last value and nth value so for this i’m going to specify first value and we need to put something in here specifically we need to put the the value expression that we want out of this in our case it is net revenue which is right here inside of our cte the next is an over and then inside of here we don’t need to do a partition by because it’s everything’s already grouped but we do need to do an order by specifically where do you what do you want us to choose the first value from in our case we want the first value based on the months not on the value of net revenue so i’m going to put month in here and we’ll give it the name or alias first month revenue going ahead and running this we can see that we do in fact get that first month into all these different columns let’s now look at last value let’s change the function name and then also the alias running this one now this one unfortunately whenever you read it you find out oh heck this is not the last month’s revenue for each of these and that’s because the actual syntax inside of here of the last value of how we need to order by needs to change specifically i’m going to delete it and put this in here and we need special conditions of to use rows between unbound proceeding and unbound following when we look at it we can see that it is actually the last month net revenue anyway just wanted to demonstrate demonstrate that because it takes a little bit more to fine-tune this one we haven’t covered un unbound proceeding or unbound following we’re going to be covering that in the next lesson so stay tuned for that one all right next up is nth value i’m going to go ahead and copy this first value and then insert it down here underneath and then change the formula name of nth value also for this we need to specify the integer expression for what number of rows after this to do so right now we’ll just do three rows down and we’ll call this third month revenue okay running this bad boy we can see that we get the third month’s revenue now we do have this nonvalue in here once again if you want to fix this which we’re going to cover in the next lesson we can insert this statement right here right after this running this we now have the third month filled in for all this don’t worry those all make sense tomorrow when we cover all those but at least you got the basics now let’s wrap up the simple example with lag and lead so for lag we’re going to be looking it’s going to be a lag so it will be the previous month we’re going to look for this returns values evaluated at the row that is offset rows before the current row within the partition if we want to it’s optional because it’s here in square brackets but we could put an offset integer similar what we did for the nth value and we’re to offset that we’re not going to do an integer for these examples we just want the previous and then use previous to find the next months so going back to our query i removed some of the other ones because i don’t they’re it’s getting too much in there we’re going to specify this as lag with the parameter of net revenue we’re going to still order by month and this will be the previous month revenue let’s go ahead and run this and inside of here we can see yep this is in fact the previous month’s revenue this does take a parameter like i said you can do that offset so if i wanted to do two in this case run control enter it’s now offset by two values before it goes down we’re not using that for our case we’re just going to go we’re doing trying to calculate eventually month over month so we’re going to leave it at one and run this okay let’s now use lead i’ll specify the formula first and instead of previous month it is going to be next month go ahead and run this and we can see that it is actually the next month’s revenue for all of these so you’re probably like luke what the heck does this even matter yeah you can find this out but how does this even help me as an analyst well let’s say that i wanted to find my month overmonth growth which is pretty common in the finance industry for evaluating your performance so here i have a chart that’s showing basically our bar chart of the different revenue each month and then the line chart is showing what’s happening what’s the rate of revenue growth month over month here we can see that in may we had a substantial increase in growth and that’s because we had a pretty low one in april anyway it’s pretty big predictor in the business world so let’s get into calculating this so in order to do this we care about the previous month’s revenue in order to calculate this so we don’t really need this lead function right here i’m going to go ahead and remove it so what we need to do first we’ll just take net revenue and subtract it by this value right here to get basically our change every single time and we’ll give it the alias monthly revenue growth okay now we can see from this that it is calculating that growth an easy line to see is row two we went from the previous month at 4 million to that month of 2 million so we lost 2 million yeah calculations are doing well okay we want a a rate of change because of this we need to actually divide this value of net revenue minus the previous month revenue and we need to divide that by our original value which is our previous month revenue so i’m going to go ahead and copy that again paste that down here let’s go ahead and run this and bam there we have it we are now calculating that rate of change and we can basically see that um for this for in march we had about a 50% reduction in revenue whereas in something like may we had almost 150% rate of growth just to be clear this is decimals so this is a the percent if i wanted to i could just do 100 times this value and then we can see this percentage a little bit easier with this so let’s get into example to show the benefit of these type of functions that can be used and previously in the second lessons of this chapter on aggregation we went in and covered what was the average lifetime value based on your cohort if you recall back your cohort you’re assigned a cohort or customers assigned a cohort based on the year of their first purchase and we notice this trend that following around 2016 we see the lifetime value drop during these and that makes sense because their actual total lifetime is slightly shorter but we did have this unexpected rise in from 2015 to 2016 anyway what happens if we want to go through and actually analyze what are these different drops between each one of these ltvs well we can use our lag function for this now in order to do this we need or the table we need to start is this we need the cohort year verse their average cohort lifetime value now we basically calculated this back in lesson two of this chapter on aggregation here i have the formula here and actually what we got to inside of the lesson was this final table which consisted of one ct and then another formula underneath it anyway i took it a step further inside the notes so for those that have access to the notes you can go right to it and all you need to do is copy this the other option just pause your screen and copy this in also this next example we’re getting into isn’t that long so you can just watch along if you don’t even want to do any of these so we need to run window functions on this after i’ve gone through and inspected this it’s a ct inside of another ct but then we have to do the select distinct because we have multiple different rows so i’m actually going to put this one also into a ct i’ll give it the name of cohort final i need to go ahead and put a closing parenthesis on this and then do a select star from cohort final make sure everything’s appearing just fine underneath here and it is okay now we can work from here to insert in and we want to create our first column to look at what is the previous year’s lifetime value so for this we’re going to be using lag i’ll do a select star to basically show both those rows and then do a lag and the value we want to put in here is what value we want actually to appear and that is the average cohort lifetime value we’ll do over and then inside parenthesis we’re going to do an order by and we’re going to order by that cohort year and we’ll give it that alias of previous cohort lifetime value and okay we’re seeing that it is the in fact the previous cohort lifetime value all right all right final thing i want to do here is calculate that percent change so that year overyear change or better that the year of the cohort over year of cohort change for this remember our ratio is a final minus original over original so i’m going to take that final value of average cohort lifetime value and then subtract our windows function so command c this command v and then from there i want to divide this by the original so once again paste in that previous cohort ltv and we’ll give it the alias of lifetime value change okay we’re going to go ahead and render this okay it’s not the correct value i expect this to be more of a a decimal number i think this has to do with basically my order of operations here i think i have that parenthesis in the wrong place i want to do the subtraction first and then after that the division okay this is giving it to us i want to actually see these as a percentage so i’m going to put a 100 at the front multiply this and bam now we can see our lifetime value change yeartoyear as expected we had a slight increase in 2016 and then from there it went down now if you actually go through and visualize this looking at this is the average cohort lifetime value uh in the bars and then the actual rate of change we can see that the rate of change actually is picking up so although i would expect it to go down i wouldn’t expect it to go down at this high of a rate so maybe something we need to dig into in a real life scenario if this was happening all right you got some practice problems now go through to get more familiar with handling these type of functions and window functions in the next and final lesson of this chapter we’re going to be going into further detail and syntax understand to be able to use like we demonstrated that last value function how it wasn’t working properly without further syntax specified to it we’re going to be going over that in there all right with that i’ll see you in the next one welcome to this fifth and final lesson on window functions where we’re going to be focusing on frame clauses now up to this point with window functions we’ve only really focused on two things of the window definition that’s the portion after the over and that is looking at how we can use partition by and order by but there’s actually one more thing to cover with this and that’s the frame clause this aspect helps control what amount of data we want to actually control putting inside of the windows function what do i mean by all this well as we’re going to be solving in this say we have something like the monthly net revenue this is from 2023 as you can see it’s highly volatile going up in february and then going back down and then going back up well this is where frame clauses come to the rescue what we can do is look before and after certain rows and in this case average them and so we could in in this case perform a threemonth running average to basically smooth out our line this is very common in business analytics especially with seasonal data that has these types of ups and downs you want to remove all the noise and actually be able to look at it more clearly so postcrest has some documentation that goes all into this but it gets quite complex so i simplified it in our notes so this lesson is going to be focusing on using the frame clause of rows basically looking at what rows we want to put inside of this window function now as hinted to this comes right after our order buy and we can either include something like the start frame or we can use that between keyword to signify a start frame and then also an end frame but what the heck are the start frame what’s this end frame well there’s five main things we could put inside of here and is the majority of this lesson of what we’re going to be getting into for we’re going to be able to see how we can use current rows preceding rows and also following rows don’t worry we’re going to break each one of these downs so you’ll be more than familiar with it by the end of this now with postgress you can also specify besides using row you can also use things like range or groups this i would classify into more of advanced sql so we’re not going to be really covering it in this course additionally i had chat gbt make this fancy dancy table down here and i want to just show with this range and groups also isn’t supported in a lot of other popular databases specifically mysql and sql server so i don’t really want to waste your time if you don’t have those type of keywords available to use that’s why we’re going to focus on rows anyway you need to learn anyway to be able to apply range and groups if you want to learn that later on now for this entire lesson we’re going to be analyzing our monthly net revenue similar to what we did in the last lesson because as you remember we had some unanswered questions on how to use some of those functions without what we’re going to learn in here we’ll get to that by the end anyway you should remember this query or have it in your system already right this goes through and gets not only the month but also the net revenue for that month pulls it from the sales table and it only extracts 2023 i just want to look at one year so there’s not a lot of data we’re messed with since we’re doing an aggregation function we need a group by and then finally need or buy because it gets all out of whack and you should see something like this looking at our monthly net revenue if we graph it looks something like this that we saw at the beginning goes up in february and then also has a strong dip down in april then returns back to normal we’re going to be working towards getting a running average with this but we first need to understand current row which the keyword of this one before we move for any further so i want to run a window function on this query so i’m going to put it into a cte we’ll give it the alias monthly sales and i’ll put it into parenthesis we’ll select both the month and also the net revenue and pull this all from monthly sales let’s go ahead and run this and it’s exactly the same thing that we saw before now we can actually run or use a window function here instead of on here like we said before can’t be using window functions with the group by we can it’s really complicated we’re not going to do it anyway we’re going to do the window function below specifically all i want to do is get the average net revenue for this month so basically repeat that same value so we’ll start by calling average on net revenue we’ll go over i’ll start a new line and indent down and then before we actually anything else let’s just look what it generates it’s going to generate the average across all 12 months so we want to do this or we want to order it by the month itself so i’ll do an order by and then specify month now running this query we’re still getting the average but it’s slightly different now for january it’s still the same and that it’s the january average but if we look at something like february it’s not only it’s getting the average based on january and february for march it’s getting it based on january february march anyway we want to control this average so let’s move forward we’re going to start by renaming this column so i’ll give it the alias of net revenue current because we’re about to use current row now this has the following syntax of rows and then the start frame we’ll eventually get to this one of rows between but we’re just going to start simple with this one first and then remember our start frame or end frame can be any one of the following we’re just starting first with just current rows where we then move into calculating the average or should i say the running average all right so i’m going to insert in rows and then from there current row now this is selecting to run this window function on this current row so there should be no difference between any of these promise you we’ll see more of an impact in a little bit but i do want to demonstrate how you can also write this rows between and we need to do our start frame so current row and our ending and we’ll do once again current row as you would expect it’s only looking at the current one so it’s going to be the same across all of these let’s get into our next keyword of looking at how we can use something like n proceedings looking at preceding rows or preceding values this is going to be the final table that we get in it we still have our monthly and our net revenue and what we’re going to look at in this case is just one row back and the current row in order to get the average right here at the first one we expect it to be the same as this one but whenever we get to the second row right here it’s going to look at this current one and also the preceding one and get an average so the average of uh 3.6 million and 4.4 million is around 4 million and so for this we’re going to use inside of our start frame we’re going to use n proceeding specifying n as a number so getting back to our query right now we have in there to do rows between current row and current row we want to go one row back and also look at our current row so i’m going to remove this portion and we’ll specify one proceeding oh not receding but actually preceding okay let’s go ahead and run this and as we saw that in that demo table we’re now taking the average of the current row and the previous row we get 4 million in this case so we can take any number of values also we could just make sure that this is actually working properly by putting a zero instead in here instead of one which means the current row and we’re getting all the same values as before but we’re going to change by back to one now i’m going to take a step further just for demonstration purposes you don’t have to do this portion but i went through and we did before we did one proceeding i wanted to see what it was going to look like for also doing two proceeding and three proceeding and i got this fancy dancy table and from there plugged it into chatbt to actually visualize it and what we can see from this is that with each preceding row that we include so we include more to take an average of it this line becomes smoother and smoother it goes from it starts with a darker line with just core net revenue and it gets lighter and lighter depending on the preceding amounts that we used i know there’s a lot of overlap here so i also took it like this and i graphed each one of them individually showing how over time it gets smoother smoother and smoother so now you’re probably like luke is this what you do in a real world scenario i’d say well not typically just the proceeding but i combine this with something like following and so we’d use values before and after the current month and get something like a three-month average which let’s do it now so just as a reminder it’s going to be of the syntax and following where you can specify the number and it gets that many number of rows after the current row so back to our original query that we’re working with instead of doing one preceding and the current row what i’m going to do is now change this to one proceeding and one following running this query we can see that all our values now especially even that first month is smoothed out because it’s not only taking the current month but the following month whereas something like june is taking not only may’s month but also july’s month and then averaging it together to get this value this i feel is more representic of what i’d see in the business world i went ahead and visualized it and this shows how this actually smooths out our net revenue line by performing this three-month average now you could take it up a notch and do something like a fivemon or even seven months uh running average but at that point i think you’re going to be removing a lot of key insights from this so i’m going to stop right here at that all right last two start frame and end frames to end with and this is unbounded preceeding and unbounded following if you notice carefully all they’re really doing is replacing the n with unbounded and this says hey we want to use all rows from the start or maybe all rows from the end so let’s actually just do just that in here we’re going to place one on these with both of unbounded and what do you think’s going to happen here well if we use unbounded on both it’s taken the entire window function or window frame into the account for printing this average so we’re basically getting the average of all these 12 months now typically when i’m seeing anything like unbounded used i’m usually seeing it with something like current row running this we can see that the first row is equal to basically itself and then as it goes along it’s taking into account all the values behind it along with the current row and it seems like the line is just getting smoother and smoother and smoother as it goes along so where am i typically seeing these unbounded parameters being used well if you remember from that last lesson when we were looking at same uh chart of the monthly revenue we were able to use like lag lead functions specifically first value last value and nth value let’s go ahead and run this we saw that for first value it actually did give us the first value but then the last value it didn’t work out properly it just gave us what the current row and then for the third most or whenever we did nth value and specified three it gave non values for the first two but then finally gave us the third value for everything else well this is where unbounded comes in so let’s fix these functions be able to do this and then i’m going to indent this down to make a new line to make this a little bit more readable and then from there i’m going to insert in our frames clause specifying that rows between and then rows between unbounded proceeding and unbounded and f unbounded following running this one now whenever we look at that last month revenue we can actually see that it actually does equal the last month basically we had to open up what it was going to look at for that window function by using this frame clause similarly we can do the same with that nth value i’m going to go ahead and just copy and then paste that right into here now running this and we can see that now that third month’s rent is appearing in every single line regardless if it’s before or after so bam we’ve now covered all of the major aspects of using window functions you now have some practice problems to go through and get more familiar with using these different frame clauses inside of window functions and then in the next chapter we’re actually be getting into and how you can install this database locally and run it locally so you can have a workflow that’s actually workable with that i’ll see you in the next one all right welcome to the second half of this course don’t know why i had to jump in like that wanted to have a dramatic entrance for some reason anyway in this chapter i’m going to be taking you through all the steps necessary in order to install postgress locally onto your computer get you set up with its editor of pg admin and then also get you set up with an even better editor of dbaver so let’s break this down in this lesson we’re going to be installing postgress or the database itself locally onto your computer we’re going to be downloading it from the internet and then it’s going to install postgress but also pg admin now pg admin pg short for postgress uh is the editor used in order to interact with postgress databases so anytime you need to start or stop the database or even if you want to run a query with it we can do that with pg admin which we’re going to demonstrate all during this lesson now if you already have postgress and pg admin installed you don’t need to do it again but in this lesson after we do the install we’re going to go directly into actually loading the database specifically our contazo database that we’ve been using in those jupyter notebooks once we get the database set up we’re going to do a quick walkthrough of the entire pg admin ui so become more familiar with it now there’s one major flaw with pg admin and that it only connects to postgress databases and after this course you may be proceeding on to learn other databases because of that we’re going to be installing in the second lesson dber now this is a database management tool so can only connect to different databases you can also run queries on it to see the output we’re going to be using the community edition of this and it’s free and open source and has everything we need to do to get started this is the most popular database tool that i know of so i’m super excited to use this and everything that you learn for using dbver can also be applied with other databases which dbaver can connect to one last note before we begin some of you may run into installation errors or other errors along the way i highly encourage you to use something like chatbt to help you out it’s a lot quicker than trying to post a comment and helping or hoping somebody else comes in to help you out now let’s say you can’t figure it out or you’re on something like a chromebook and can’t install postgress in that case you can continue to run all of the different queries in our sql notebooks they’re going to work exactly the same and have the same output but as far as interacting with the guey and stuff like that you’re going to have to figure that all out yourself because obviously it’s going to be different than deep so first we’re going to navigate to the download page from postgress and from there you’re going to select your operating system that you’re currently on i’m on a mac so select that we’re going to be using the interactive installer by edb so we’re going to select right here of download the installer which everybody regardless operating system it’s going to get navigated to this page where you can then select your operating system once again and download it for mac or windows you’re going to want to launch this installer if it gets a warning message it’s okay click open it we’re now going to walk through the actual setup wizard that it has included for all this we’re going to leave all the defaults the same core things that we do want to make sure are installed which are by default our postgress server and also pg admin which is the guey interface next is the password and i’m actually going to set this one to a really easy one of password now my database i’m not going to have any confidential material on it and this database that we’re installing isn’t secret at all so i don’t care if somebody else accesses it but it doesn’t really matter because it’s local anyway so other people can’t necessarily get to it unless i have it access to the internet anyway that’s a long story key thing if you’re only going to be doing this course with this feel free to just set it to password you should be okay but if you’re not set it to something else and remember it keep the port number the same of 5432 it’s common to postgress databases and we’ll keep the default local and we’ll go ahead with this setup’s complete i don’t need to launch this stack builder exit i’m going go ahead and click finish and i’m going to verify this is now installed by going to my applications folder under postgress 17 i have these different options of what’s installed we’re going to be opening up pg admin this is the guey interface for interacting with our postgress database it’ll start loading up with this open we have two main panes in here we have our lefth hand side pane which is our object explorer which shows all the different databases we’re connected to right now it’s asking me to connect to the server specifically postgress 17 which is the one we installed so i’m going to go ahead and put that password in of password and i’m going to click this of save password so as we can see postgress 17 is a server we have one server and then from there we have databases inside of that server right now we only have this one standard database that comes in all postgress uh servers called postgress we’re not going to touch this bad boy i don’t really care about it but we can see that hey there’s only one database in here we also have options to adjust login or group roles and then also table spaces we’re also not going to be messing with any of this this dashboard over here on the right hand side i find pretty useless it just tells me when i have interactions inside of my server and when it’s getting used so now let’s install the kazo data set locally for this we need the database file for it which is right here of this kazo_100k.sql file it’ll go ahead and start downloading you don’t need to do this but i went ahead and opened this file just to show you the contents and in this it walks through actually creating all the different tables that we need inside of our database along with loading in all of our data into it it’s pretty long file so let’s get this file into a database and for this we need a database for this so we’ll rightclick databases select create and database we’ll name this contazo_100k keep all letters lowerase the owner will be maintained as the super user of postgress so we can use that same password to access it we don’t need to change any of these other settings right here they’re all good enough we’ll go ahead and click save now we can see we have two databases underneath here and it automatically dropped everything down underneath here now if i go under schemas and then it has a public schema i can see underneath tables if i click this to actually drop it down to see any tables there’s no tables inside of it so this is where we need to actually load that sql file into this database first thing you need to know the location of where it is i recommend just put it on your desktop we don’t need it after it’s done so you can just delete it back inside of pg admin i’m going to rightclick that contazo_100k database and i’m going to go here to psql tool this is effectively like using a terminal to interact with our database i’m going to start this command off with a forward slash then i this is going to tell it to execute the script that we’re about to insert into this and so inside of single quotes i’m going to then put the file location and i’m going to insert that in of users luke bruce desktop and then the sql file itself make sure that it’s exactly right on a mac if you go to the file itself click option and then rightclick it you’ll get this option here of copy the sql file as path name on windows all you need to do is shift and rightclick the file icon and select copy as path okay we got it in going to go ahead and press enter it says that pg admin like to access my desktop yes i want to allow this and it’s going through here and actually creating all the different tables and altering them and i can see from this that we’ve put in it looks like six different tables and it tells us all the different counts of the rows that we inserted into those tables so i’m going to come in here and go to tables and try to see it there’s no tables in here but all i need to do is just right click ino select refresh so now it should have it and we can see scrolling down the tables we have six tables inside of here which from this menu i can actually dive into in the case of sales actually dive into the different columns and everything else that has associated with this i can also just do a quick check of this by rightclicking something like the sales column going to count rows and it tells me at the bottom there’s over 199,000 rows in this sales table but how can we actually query this database of contazo 100k well first we need to make sure that it’s actually selected and then come up here and select query tool we can also see that they have a shortcut of option shift q it opens up in a new tab right here i see these other tabs here if i don’t want any of these other tabs i can go ahead and select x and close it out up here at the top it tells me which database i’m connected to if i had any others i could switch it right up here we have our query window which i’m going to put in a simple command to look at the sales table and the top 10 results to run this i’m going to come up here and select this play icon for execute script or i can press f5 and all the results are displayed here below i also have this scratch pad over here on the right hand side so if i don’t have queries that i want to keep track of i can just put it over on the right overall i don’t find myself using it that much other key features of this area are you could open a sql file right inside this window or if i want to save this i could save the file we also have options for explain which we’re going to go into more detail in some upcoming lessons now down here at the bottom we only have the data output but also any messages and notifications inside of that output they actually have a few unique capabilities with this in that you can copy any of your different exports of data out of it if you want to put in gbt or something let’s say we have a more complex query that actually does some analysis such as this one right here that looks at the total yearly net revenue well we can not only save results to file but also we can graph and visualize it right here i select line chart and then we want the year for the x-axis and then the total year net revenue for that y-axis and then select generate and not too bad to actually get into visualizing queries pretty easily in this last thing to note with pg admin is i can also do things like view the erd or the entity relationship diagram for the database by rightclicking it select erd for database and with this this is showing our sales table i can scroll in through this and actually see the sales table along all the different keys and columns in it and with this table how it’s connected to all these other different tables in it so a great way to visualize your database and tables that you’re working with all right we now have some practice problems for you to go through and get more familiar with this pg admin guey like i mentioned at the beginning we will be transitioning next to dbver but i do find myself from time to time having to jump in and use pg admin so it pays off and understanding the basics of this tool that’s why you got those practice problems all right with that i’ll see you in the next one welcome to this lesson on dbaver in this we’re going to be walking through setting up and getting dbver connected to our contaza database first thing we’re do is going to download the community edition of dbver which is free then from there walk through the steps necessary in dbver to connect to our postgress database and then finally once we have that set up we’re going to actually do a walkthrough of the dber ui understanding how we can run different scripts and how we can set up our project inside of it all right with that let’s get into it all right if you navigate over to dbeaver.io this is the homepage of dbaver community this covers a few details about the tools you can read further specifically dbe community the edition we’re downloading can connects to a variety of databases and has all these different editing and viewing options it’s by far talking to all my data analyst friends and also looking at the research it’s the most popular database editor so that’s why we’re using it now dbver needs to make money like any community so they also have a pro edition i’m going to go ahead and click this you don’t need to and so with that they have a few different edition editions that you can get and use some get pretty pricey if you’re a business but as far as the basic sql and coding that i run i don’t ever need the features that are inside the light enterprise or ultimate edition i can get it all done with a community edition but if you come a power user highly encourage you you buy a subscription because you support building out dbver further all right cool story luke let’s actually now get into downloading db and close the download and then from there you select what operating system you’re on and install it i’m going to be going through with mac windows is going to be very similar so i’m not going to cover them separately after your installer file loads you should click it and open it up on mac it’s pretty easy all you have to do is drag the beaver over into your applications folder and now it’s here i’ll go ahead and open it up if it asks if you’re comfortable with opening this app up yeah we know where we got it from i’m going to open it with dbaver opened up and launched um you may notice first that mine may be dark and yours may be white i have dark mode enabled on my mac so i guess it automatically picked it up change it to dark mode anyway it says “hey do you want to create a sample database that can be used as an example to explore basic db or features?” we’re not going to do that we’re going to just install the contazo data set and then i’m going to take you through this so it should have immediately popped open with this of a connect to database and now we’re going to get into installing the database if this select database didn’t pop up that’s okay there’s a few different ways you can get it up and we need to go through it anyway one other thing before that it does have this popup that says “hey do you want to share your data in order to improve performance i’ll leave it up to you on whether you want to do this or not.” so to create a new database connection you can either go up to the file menu and go to databases and select new connections or you can just come right here to this fancy dancy icon and select new database connection now this is one of the reasons why i recommend dbver so much is because it connects to a host of different databases and so that way you can connect all your different ones that you’re working on as a data analyst so in our case our canazo is a postgress database we’ll select that now we need to go through and fill out the connection details we’re going to be connected by host specifically our local host so it’s locally on your computer the database name is not postgress it’s the contazo 100k make sure you spelled exactly the same as what’s appearing in pg admin next we’re going to move into the username which we maintained it as postgress and then the password if you named it like me the password is just password all lowercase i’m going to leave save password enabled because i don’t want have to log it in every single time from here it’s already picking up that we’re using postgress 17 and everything else looks good let’s go ahead and test connection in my case it’s saying that the postgress driver files are not installed we need to install them basically like if you install a printer into your computer or attach a printer to your computer you have to install driver files to attach to it so similar here nothing wrong with this we’re going to go ahead and download with that we get our test results back and it says that we are connected now if you are not if you have issues with that one check all those credentials make sure they’re correct but two what may happen uh to you is that your database may not be started and so you may need to open pg admin and actually open it all the way up to the kataza data set and make sure that it’s actually running on your machine typically for both mac and windows your postgress databases should start when you restart your computer so you shouldn’t have to do this but you may have unintentionally disabled this feature and so you may have to restart anytime you restart your computer with all the credentials put in and the testing of the connection set we’re going to go ahead and select finish so let’s now walk through dbver and get into understand the ui and also running a few different files okay so we have this pane right here on the left hand side and that is our database navigator also it holds our different information on our projects which we’ll get to projects in a minute anyway this has all of our database information in it if we want to see it specifically underneath database navigator if for some reason this disappears like i accidentally close out of it you can go into the windows menu item and from there show the actual view of database navigator pop right back up so what’s inside of here well very much similar to what we saw in pg admin we can see all of our different databases in here we have our contazo 100k database we also have these folders on administer and system info these are ones that i’m using less i’m typically staying inside of here specifically inside this contrao 100k go into schemas under public because it’s the public schema we care about and i can go into actually viewing all our different tables if i drop something down like the sales table i can see if i wanted to go into all the different columns in it along with what is the data type of those columns i can also see a host of other information like foreign keys and whatnot anyway one thing that you may have noticed about this is that there are numbers over here on the left hand side these aren’t the number of rows but instead if you hover over it you can see that it tells you how much disk space that that specific table takes up so you can get a general idea of how big these tables are just on dispace alone so i can see that sales and also the customer table specifically are pretty big relative of course this is actually a pretty small database now what i like about tools like dbaver is how easy it is to dive into these tables without having to write a sql query specifically if i wanted to see what was in the sales table i can rightclick it and then just go to view table now this side is the database editor and it actually has a tab view it’s like i could do something like this open also the currency exchange and it has multiple different tabs that i can cycle through now with this i can view a bunch of different things underneath properties i can look at all the different columns foreign keys constraints whatnot next up is data i can obviously look at the different columns inside of here and scroll through it a lot easier similar to excel spreadsheet and then the other one is the er diagram or the erd and this shows how your tables are connected all together i actually feel compared to pg admin this one is more realistic and shows how they’re all connected whereas i don’t know if you remembered from pg admin but they all like connected into a single line and went all over it was a hot mess so db does a little bit better at this anyway the view that i’m typically looking at most is this data one right here and i can look at as a grid or also as a text text i don’t find very useful at all um except if i need to copy and paste it grid is mostly where i’m staying now this guey in here has a lot of different options that you can use to interact with these tables and view them specifically you could enter a sql expression to filter it down you could also actually put in custom filters in here to filter it down down at the bottom we can do things like add rows remove rows typically i do this with sql i’m not going to mess with it here in dbe can also cycle through the different pages and whatnot one that i do find useful however is this of export data and anytime you have any of your data that you have and you want to get it out of here you can put it into a variety of different sources typically i’m doing something either of exporting it to a csv or export it to sql which will make it into a sql insert statement all right so enough of that let’s actually get into setting up our project folder i don’t need these two tables open up it’s also asking me if i want to save these changes in the data set database i didn’t really change anything or i don’t want to change anything so i’m going to click no so we’re going to be creating a project folder i’m going to click projects right here in order to be able to save our sql files if we want to as we go along right now we just have this general right here which has bookmarks dashboards diagrams we can also see it right below here i don’t really care about the general one i want to now create a project specific to this course that we’re working on so i’m going to come up to the top right here and select create project and i’m going to call this intermediate sql project real original i know with this project i’m going to leave it to the default location which is inside of the dbe folder i could uncheck this and then re change that to wherever i want it to be just so you’re aware i’m going to leave it in the default location i don’t want to add the project to a working set so i’m going to go ahead and select finish so now i have this intermediate sql project and my general my intermate sql is my main project or my active project so i’m actually going to rightclick it and say set active project and then it should shift to bolded additionally if i go back up to windows in the file menu and go over to project explorer i can have that now appearing below if you didn’t close it out it was general probably it should have switched to that anyway i like this type of view because now i can switch between them but if you notice the database navigator we now don’t have our sql database in there anymore so what we can do is go back to projects and it actually makes it pretty easy in here right here under general i have the kazo but what if i tried to click the connections of the intermediate sql project there’s no database that it’s talking about so we loaded the database into general we want it to move it over down here and so bam now when i open this project folder which it’s the de uh the default one in this case now it’s inside of here in the database navigator as well so this is pretty neat of how i can keep this all grouped together in a single project now by default there’s four different folders in here they all should be empty of bookmarks dashboards diagrams and scripts bookmarks are just as they imply bookmarks if you have something that you frequently go to you can just put it there in this case let’s say i frequently go to the sales table i can stick it in bookmarks and now makes it super easy anytime i need to go to that just click on it and bam it appears right here next we have dashboards and nothing in this but you could create a new project dashboard if you remember from pg admin they had a actually a default dashboard that shows all the different sections transactions stuff like that i’m not a database engineer i don’t really care about all that so we’re not using that next are diagrams if i wanted to i could create a new erd i could call it contazo erd now this does have our five core tables in here but also it has a host of other different tables that just come natively inside of a postgress database whenever you install it so they’re all going to be there if you make it this way you can filter down we’re not going to go into that all right the last thing is scripts how the heck do we create a new sql script well you can do this from sql editor in the menu or just come up to the top here and select open sql script now there’s a few different options that popped up here since we’ve done this first it tells us what is the active database and it tells us what is the active database schema so this is especially important when you’re working with multiple databases to make sure that you’re running the queries on the correct database now notice whenever we open this up inside of here we also the script itself we also have a new script underneath here i’m going to go ahead and minimize these we don’t need this anyway we have script inside of here if i wanted to i can rightclick it and go to something like rest rename and then we can name it appropriately like this is just a test script and i’ll make sure that’s a sql file press okay and it’s since been renamed so let’s run our first sql query we’re just going to make a simple statement of we want to select all columns from the sales table and we want to limit this to 10 results if you notice this i was typing in all caps as i was going along and then it made it lowercase after we’re going to fix that in a little bit anyway if i want to run this single query on a mac i’m going to press command enter on windows i’m going to press control enter also if you forget you can just scroll over these icons and click it and it also gives you what the shortcut is now similar to what we saw before with how we can view different tables and outputs i’m going to have a tab here and then underneath this i can actually explore it in different ways with text or grid i can also cycle through it if i want to export the data so a lot of different options to manipulate this and dive into all of it let’s run a slightly more complex query to just demonstrate the the power of this i’m going to make this into a cte and then we’re going to run a query on that cte so i’ll enter this down put in a width keyword we’ll call this sales copy because that’s what it’s going to be give it the alias of as and then open parenthesis now i need to clean this up i like indentations and things like that i can actually highlight this all rightclick it and then go into format and i have this option for format sql on a mac the shortcut is control shift f so i can actually just do that instead of doing control shift f and it makes it slightly more readable although it didn’t end in anyway as always with any ct i’m going to go down here and do select and star and then we’re going to be doing this from the sales copy table above now if you notice this it automatically gave me this error message saying “hey sales copy is not located above.” and actually if i even tried to run this with this by pressing command enter um it tells me sales copy doesn’t exist but i can clearly see that it’s up here that’s because dbaver automatically treats any blank spaces or blank rows as a endline delimiter basically treats it as like a semicolon at the end so what we need to do is subtract that out of there and i’m still getting an error message i don’t know why i am but oh it’s running now and it cleared okay i just had to run it once anyway i don’t like those two things right now i don’t like how it’s automatically making everything lowercase and i don’t like that it automatically gives me this error message when there’s just a space in there so we need to change some settings before i want to proceed on if you’re on a mac you’re just going to select dbeaver up in the menu and select preferences on a windows i think you’re going to select file after you select settings this preferences window will open up and this allows us to go in and actually control things inside of the editor itself i want to control things in the sql editor specifically for the formatting right now the keyword case is set to default which is lowercase i want it to be upper so i’m going to change it to that you can also control your indent size down to like two i like bigger indents so i’m going to do four also if you notice previously it wasn’t indenting in those things that are in parenthesis i like that so whenever i click this it does indent it in so i’m going to have that selected as well last thing to uh update is under sql processing and moving this over in this we have blank line is statement delimiter always we remember sometimes we may have blank lines in there i don’t really like this setting so i’m going to change this to never you can also change it smart but i’m not guarantee it okay we’re going to do apply and close now i’m going to select all of this press control shift f and it formats it exactly like i like so basically it changed all those keywords to uppercase and indented it in like i like not too bad now that was just one query i could put a semicolon in here and then let’s say i wanted to do another query on top of this i can keep it in the same script some things i didn’t call it before but anytime we’re typing any words you’re going to have this autocomplete and it also tells you what is going on there similarly if i’m doing something like a function count in this case it tells me hey it’s a built-in function in the database i can use this and then after i insert something like from it also it automatically knows hey he probably wants to put in a table so i could put something like customer in here now i have multiple scripts inside of here so what i could do is if i just want to uh enter this script i’m going to go ahead and close this out down below if i just want to do that script right there i’m going to press command enter and it’s only going to run the one script tells me there’s 104,000 rows now the other thing i can do let’s say i want to run all of these scripts they have this icon right here for execute sql script for me it’s the shortcut of option x on windows i believe it’s alt x i can go ahead and well we’re going to close out of this first we’ll select here and press option x and it automatically opens up each of these in different tabs now one thing to note is like okay how do i keep track of what are all these different queries that i ran right here well you can put a brief comment up at the top using two dashes and we’ll call this one sales copy and then the one at the bottom we’ll call this customer count now running this again pressing option x it prompts me hey there are three unpinned results tabs do you want to close these tabs before executing the new query i want to do this all the time if i’m running a new query i just want to see the new results so i’m going to say “hey don’t ask me again.” and i’m going to say “yes i do want these closed.” and that didn’t work because i actually told you wrong we need to you need to actually specify that this is a title so you specify title colon and then whatever it needs to continue on after that for what the title is i’m going to do that for both of these press option x and now both of these are named both below this is very convenient when you have multiple queries and you’re going to have obviously multiple different tabs also there is this one of the statistics tab basically just tells you the statistics that it ran two queries how long it took and whatnot so now with this test script that we’ve created if i wanted to i can see that it’s not saved because it has an asterisk i can go into file and select save or press command s or control s and the asterisk went away and now i can close it and if ever wanted to go back to that certain script i can just pop it up here and run it as necessary bam so now hopefully you’re follow along and you went through and installed dbaver because you need to do that unless you plan on using uh jupyter notebooks or collab to run the future queries anyway we now have some practice problems for you to go through and get even more familiar with dbver of all these different settings and actually getting familiar with running sql queries with that we’ll be jumping into the next chapter on building views so that’ll see you there welcome to this chapter on views now views only takes up really a small portion of this the majority of this chapter is going to be an intro to the project using views now in this we’re going to be going through three lessons in this lesson specifically for this video it’s going to be an intro to views how to create views how to delete them how to manage them and why they’re so important in the second lesson we’re going to be using that view that we’re creating in this lesson in order to analyze it further and answer one of our second questions in our project now our project in total has three questions which i’m going to showcase here what we’re going to be doing in a little bit and you may be like luke what happened to question one well question one we actually answered or start to answer it earlier in the lesson we’re just going to be building on it further in some future lessons don’t worry i’ll be getting you up to speed okay and then the third lesson that we’re going to be getting to in this is actually installing vs code which is a code editor that makes it super easy for us to build up our portfolio project and then share it onto the internet now before we get into views i want to just showcase what we’re going to be building in this project specifically we’re going to be sharing this to your github profile and it’s going to detail everything that you’ve done now if you’re not familiar with github this is a location that you can store and also share or collaborate on files here in this uh menu area this shows all the different files in this repo as we can see we have some sql files and then a readme which i’ll discuss more in a little bit and then we have like something like this which is an images folder if i click on it i can see that they have something like image inside of it anyway getting to that readme the readme on the front page of a project is going to be displayed right below it so here i can go through and actually document all the different analysis that i’ve done so if i have some employer interested in different analysises that i’ve done they can come to my github and view all that here and now you may be like luke why the heck do i need to install vs code you already had me install dbaver what the heck am i doing with this well vs code if you’ve taken my basic course you know is really powerful not only in writing sql queries but also in other coding projects like using python or whatnot anyway what the special use case in this project is is actually building our readme here i’ve typed out all the different portions of the readme and if we actually view it here i can see it all dressed up on the right hand side how it’s going to appear on something like github unfortunately dbaever doesn’t have these capabilities along with the fact that i can also go through and push this and put this onto github right here from this guey so loads of benefit those that have come from a basic sql course you’ve used vs code you’re familiar with it there’s not going to be a lot of stuff new that i’m covering here you’ll probably be able to even skip this lesson on vs code so let’s get into views well first of all what the heck is a view it’s a virtual table that allows us to show the results of a stored query in it for example we’re going to be going through in our next example and creating a view you can find underneath the views folder underneath a public schema and we’re going to create this one called cohort analysis whenever i click on it it’s that virtual table so this is a has all the different results for a certain query specifically i can go here under properties and look under source and actually see what was the sql query taken to actually generate this virtual table and so with this virtual table in this case it’s called cohort analysis i can open up a script i go ahead and clear all this out and say i want to select all the rows from the name of the view cohort analysis is even appearing right here telling me that it’s a view when i run it i get all the results of it below now views are super important and are necessary to level up your sql skills they allow you to or basically prevent you from having to go through and write the same query over time and time again because you know what happens whenever you have to write the same query over time and time again you’re eventually going to make a mistake with a centralized view this prevents that and also ensures that if you have this dedicated view that any other queries that depend on that view will get updated if for some reason you have to update that view anyway i’m getting ahead of myself what’s the syntax for this all it is is we need to use the keywords create view give it an alias and then provide all of our different sql that we had below it to actually go into that view so let’s go in to create our first view i’m actually going to go ahead and delete this view that we’re going to create because you don’t have it yet for this just open up a blank script in this we’re going to do a simple query that allows us to get the daily revenue for this we’re going to use the order date and then also we’re going to use the sum of quantity times net price times exchange rate and give it that alias of net revenue this is from the sales table and we need to perform a group by since we did that aggregation all right let’s go ahead and run this bad boy and it looks like it’s done all correctly one thing to note i didn’t filter this or put this in any order one thing to note is you can actually do that in here i can just click one of these filters and say hey order by we’ll say in descending order and it shows me okay we start in april 2024 and go backwards with the total revenue pretty neat all right so this is the view or that we want to create so let’s create it using that syntax specifically i specify create view give it the name of daily revenue and then just use as don’t need to put this in parenthesis i’m going to go ahead and run this pressing command enter and you should get something like this at the bottom telling me that the query is in fact finished now if i go to views there’s nothing there what i need to do is i need to actually refresh it you could do this by right-clicking and clicking refresh or you see the shortcut right here of f5 i’m just going to do f5 so now in this case that daily revenue is there i can double click on it open it up it has a few different tabs underneath it like i said the properties underneath it so we can see something like the source which gives us that query that we needed to create the view so we don’t need to save our query separately it’s right there it also shows our data and then finally our erd in this case it doesn’t really connect to anything else just its own table bam that’s it now if i wanted to access this view all i have to do is just do select star and specify i want this from daily revenue and since i’ve put that semicolon in the last one it’s only going to run this one when i run command enter now all the results are appearing below okay let’s say i’m done with this view or i don’t need this view anymore there’s a couple ways i can get rid of it i can rightclick it and just come down here to delete it’s going to then prompt me are you sure you want to delete this view of daily revenue and it asks do i want to cascade delete basically if there’s other views based on those views it’s going to delete all of those as well so you need to decide whether that’s applicable or not and then click yes or no or not we’re not going to actually delete it via that method and i’m just going to confirm it’s still there by refreshing this and showing that it is in fact still there instead we what we can do once again put a semicolon i can do something like drop view as a keyword and then specify that view of daily revenue okay let’s go ahead and run this pressing command enter it tells me underneath it was completed pretty quickly and coming over here pressing f5 we can see that view is no longer there very important note is that deleting views is permanent you can’t recover it once you do that so make sure you really want to in fact delete that view now that we got the basics of views let’s actually get into creating the view needed to answer a few of the different questions we’re going to be answering in our project once again a reminder we’re only going to be answering three questions for our project and we’ll be working on that second problem in the next lesson anyway you haven’t created this yet but this is what we’re going to be getting to eventually and like i said we’re going to have our view in here our different sql files to answer our three questions and then our readme this create view is what we’re going to start working on in this lesson we’re not not going to necessarily finish it in this lesson we’re going to finish it in the text cleanup lesson but we’re going to get a little bit of a start so what the heck does this view actually provide us that we’re actually going to use so we’re going to be diving into shortly a more advanced cohort analysis than what we’ve done previously and we need a table a view if you will to help us out and speed up that analysis specifically this table is going to be basically broken down and aggregated to provide us key things about a customer specifically when were their orders how many order they had when was their first purchase date what cohort they fall into and then additionally some customer information from the customer table this is going to be super helpful especially for something like total net revenue which does that quantity times net price times exchange rate it’s just already there i don’t have to worry about the calculation everything’s there so let’s just start building this view and we’re going to be doing this by just checking out our query we’re going to start with the sales table only bringing in the information we need first i’ll do a select statement we’re going to do select starf right now and then we’re going to be coming from sales now we’re actually going to be doing multiple tables in this so i need to go ahead now and i’m just going to add this alias of s i can also press tab and it adds that and then running this we can start picking out things that i want out of this with this actual table below i know i want the customer key along with the order date as always i want that total net revenue so i’m going be doing quantity time net price times exchange rate and giving it the alias of total net revenue we’re going to do one more thing also to get a count of the number of orders and we’ll do this off of the order key now because we do that aggregation we got to do a group by and i’m lazy i’m just going to go ahead and copy this up layer and place it below all right let’s go ahead and run this looks like i got a typo over here look at this syntax highlighting helping out to figure that out running it now bam we got our results that we want below everything look like it’s aggregating correctly now with this table i also think want things like the first purchase date and the cohort year this is going to take window functions going to do remember i don’t want to put that in a group by so we’re going to need to create a cte and then do it anyway what i’m trying to get at is instead i’m going to move over here to the customer information and we’re going to extract some key customer information to put into our source table so we need that from our customer table because of that i’m going to do a left join which allows us to keep all that information from the sales table and thus attach any related things from our customer table attached to it i’m going to give the customer alias of c and we’re going to link this on the customer keys of both tables i’m going to just run this to make sure we have no issues okay it’s running just fine so what information do we want to add on i’m going to do a c do star so we can add all of it on we’re going to actually refine it down and it’s telling me i need the c.customer customer key in the group eye we won’t have to keep this but this will just help clear up this error that i’m getting from using that let’s try that again all right so now scrolling over we can see that we start to have the customer information in here so i want things like the country full the customer’s age the customer’s given name and then also their surname and that should be it and now we need to put this all in the group eye because remember we’re doing an aggregation right here so i’m going to come down here and actually put that underneath here clean this all up and then we don’t need this customer key anymore i don’t believe so i’m going to remove that now let’s try to run this query make sure it goes and everything looks good we have all those different columns in it okay now what we need to do is extract out for all these different customers here what is their cohort year or the year of their first purchase so what i’m going to do is put this all into a cte i’m going to indent this over and then also space it down so we can put that width and i’m going to give it the alias of customer revenue assign it as do an opening parenthesis and then finally a closing parenthesis then to make sure that this is all correct i’m just going to do a select star from our customer revenue running this we can see that okay it is providing the exact same information that we had for run a good path now we need to do window functions in order to basically use that order date to get what is the minimum order date for a customer in order to assign that cohort year so for this i want everything from our customer view table i’m actually going to give it the alias of cr and i’m going to do cr.star star and then i want to get that minimum order date so we’re going to do minimum specifying our order date there’s a window function so we’re going to do over and then we want to partition it by the customer key so like 180 here we want to look at that and see what is the minimum of this and then we’re going to give it an alias of first purchase date okay let’s just go ahead and run this to see how it’s doing and we can see so something like rows two and three we should see for i got to expand this out we should see the minimum order date is 2018 in this case also 2023 so the cohort year for this or the minimum purchase date should be 2018 which it is now we can go ahead and build another column for cohort year and all this is going to be is just a copy if you will but we’re going to be using extract and then with that we’re going to just be copying the contents above of that minimum order date pasting it in here and then giving it the alias of cohort year let’s go ahead and run this rushing too fast i realized okay i have to extract something from that window function right i have to extract year from the windows function so now let’s try to run this we can now see that for customer 180 and rows two and three it is in fact the cohort year of 2018 this is good so now let’s create this into a view that we can then reuse we go ahead and enter a line down here we need to use these keywords of create view we’re going to name this cohort analysis and then once again we’ll use that as we don’t need to put it all in parenthesis though okay let’s go ahead and run this pressing command enter and it ran and super fast the view is if it’s not appearing remember we need to run f5 and now it’s appearing underneath here shows all of our different columns in here on the dr diagram also on the data tab so now with this analysis it makes it super simple what i can do is just create a new well i need a new script so i’m going to say new script here let’s say i wanted to analyze something like the total revenue per cohort super simple now to do with this view i specify obviously that cohort year the sum of our total net revenue and then we want to do this from our actual view which is our cohort analysis we did an aggregation so we need to do a group by specifically on that cohort year running this we can see our different results i didn’t do an order by i’ll just actually use this and order in descending order and so now in a super simple query i can get that at a lightning speed because i don’t have to do all that other analysis that i did before in that view because it’s already captured before we wrapped up this lesson this is a future loop as you can tell i’m in a different flannel we made a little bit of a mistake in our view specifically with naming a column that with the number of orders i didn’t give it an alias what do i mean by this okay going into cohort analysis anytime i want to use it i’m going to press f5 to just make sure that it’s fully up to date and if we go into the data we can see that everything looks like it’s fine except here for this column this is the number of orders but we left it unfortunately as count and that’s not a descriptive name we really need to change it to a more descriptive name and so this problem actually comes up quite frequently so this is actually good use case to go through anyway as remember when under properties and underneath source we can see all the different code now unfortunately with this command right here create or replace view previously we just saw create view create or replace allows us to replace it if it already exists now unfortunately i can’t come through here and update count here as num orders because that’s what the alias i want it to be and then this countdown here as numbum orders and then if i wanted to run this if i clicked save down here it allows me to say hey do you want to execute this it says cannot change the view column count to num orders instead you should use something like alter view or rename column to change the name of the view instead now alter view is a great thing to know of and what it can do you can go through and add additional columns remove columns and in our case rename columns so we’re just going to use this syntax to rename it but that’s only going to be a partial solution we’ll see so we’ll use the keyword of alter view we’ll name the view itself of cohort analysis and then we’ll use rename column also they have the syntax highlighting saying that it’s wrong because the table reference expected don’t worry about this it’s actually a f a false warning it’s not correct and so what column do we want to rename we want to rename that count and what do we want to rename it to is numbum orders now going ahead and run this command enter looks like it ran fine when we come back over here we can see that has a star next to cohort analysis that means it updated so we need to press function f5 we need to select inside the database navigator sorry press function f5 to make sure that it updates and i would actually recommend just closing out of the old one because we’ve changed some properties in it if you didn’t do it already and so we don’t want to mess with this we want to see what the newest one looks like so it says hey do you want these changed to persistent database no i don’t want them to so clicking cohort analysis again to get the newest up to date we can see that okay it doesn’t it didn’t change count up here but it did change it down here to give it the alias as numbum orders and i’m a perfectionist and also this is just good practice in general i want to change it in both locations in order to do that we actually need to drop this view like dropping a table and then create this view again so what i’m going to do is just copy all of this code we don’t need this alter view script anymore i’m going to go ahead and paste that in here remember we want numbum orders right here and then down here since we’re actually using it we can actually just remove it now before we run this create or replace view we need to actually drop this view this one’s simply written drop view and then we list the view name of cohort analysis i’ll put a semicolon after this and then i just want to execute this entire script right here so i’m going to press option x and it said hey it ran those two queries and it got done with it once again i’m going to close out a cohort analysis just make sure we have this select inside of here press function f5 and open up cohort analysis looking inside of our source and we can see that it updated numbum orders in both locations so crisis averted with getting that column up to date and keeping our query concise all right now we have a few examples for you to go through and get more familiar with creating views we’ll be using some of the previous examples that we’ve done in previous lessons in order to build views with so you can reuse them in the next lesson we’re going to be building further on this view that we just built in order to answer that second question in our project to further analyze the cohorts all right with that i’ll see you there welcome to the second lesson and in this one we’re going to be diving into a question for a project specifically how do customers in a particular group generate revenue regarding the particular group we’ve broken it into groups before doing cohort analysis is what we’re going to continue on from this now spoiler alert for this analysis we’re going to be looking at the different cohort years and at the customer level seeing how they spend money specifically seeing how they spend over time if you will generally it’s good practice to have customers spend more because it means more money and so we would expect that over time a company would learn and be able to extract more value out of customers unfortunately we find out just the opposite so let’s quickly reexamine what we’ve previously done on cohort analysis i’m not going to walk through this entire query we did this inside of our window functions chapter and with the results of this query we were able to plot out and see how what is the impact of a cohort on future years total revenue so as expected net revenue is going up and there’s contributions to these net revenues every year from previous years specifically members of previous year’s cohorts because your cohort year is based on your first year purchase so honestly this didn’t really uncover a lot for us does it tell us really that much we went even further and also did an analysis looking at the number of total customers and from this we saw that it went up as well once again not a lot of insights from this so what do we need to do well using our previous view that we created in the last lesson we’re now going to take that a step further and we’re going to analyze for the total revenue and the total customers but then finally get what is each individual customer’s revenue well on average at least so let’s jump into building this query for this we’re going to be using that cohort analysis i can dig into it and see that it contains all the same values that we did in the last lesson but from this i want to get based on the cohort year what are the total number of customers using that customer key and then also that total net revenue for that cohort so for this i’m going to start a new script and i’m going to go ahead and fill in the from specifically from cohort analysis and i like to do this mainly because when i go to fill it in if i do something like cohort year which is what we want one i can see that this column does in fact exist and also it does the correct syntax highlighting as i go along now with this we want to get the total customers per year so we’re going to do a distinct count so i need to do count or distinct inside of count specifically on that customer key we’ll give this the alias total customers now we need the sum of the total revenue so inside of our sum function i’ll use that total net revenue and we’ll give it the alias of just total revenue all right we did an aggregation function so we need to do a group by on that cohort year okay let’s go ahead and run this and just see what we have so we get back those total customers and then the total revenue now let’s look at this visually because i think it’s important to understand why we’re actually taking this a step further diving down to that customer level to analyze this well here i’ve plotted it where the bars are the revenue so you see it on the left hand side and then the line is the count of the total customers which is over on the right hand side as expected you can see that these lines basically correlate well to an extent to the size of the bars themselves so simply put mo customers equals mo revenue which that’s nothing new here and that’s not really any new insights that you’d go to your boss and tell them we actually need to dive deeper into finding out some key characteristics about the customers to actually give them insights of what their spending habits may be like so let’s get this customer revenue all we’re going to do is take our total revenue up here and divide it by the total customers itself and then we’ll give this the alias of customer revenue i’ll go along and run this query and now we have the customer revenue on the code here just a shout out to that views table look how simple this query is now now that we have the data in that view that makes this super uh quick to actually do this anyway back to actually exploring this customer revenue revenue over time we can see that it’s basically dropping over time let’s look at it visually and with chad gbt plotting this i have it showing that over time these customers spend quite a bit i’ll be honest uh they’re at around $3,000 per customer but then it starts to go down this is a exponential trend line that i had chad put on there anyway this is concerning that customer revenue or the per cohort year their revenue is dropping year after year i would expect like i mentioned at the beginning that either remains the same or goes up over time that’s not necessarily a good thing for this now i will say this remember that older cohorts so we’ll say in this case cohort 2016 they have all these years to contribute to their cohort so you could be part of cohort 2016 and also buy something in 2024 and so i would expect in general that earlier cohorts would have a higher customer res revenue so we need to adjust our query to account for this but you may be like how the heck do we do this do we use some sort of window function and limit the time of each of the cohorts and what is that is it like one day or one year that they’re in their cohort that you allow it to attribute to the customer or to the revenue for that cohort well i actually did some further analysis on this you don’t need to actually run this query and what does it show well we’re not going to walk through step by step all the parts of the query because that’s not important the main thing is what it provides out of it and that’s that what i have it plotting or what i had it do is go out and calculate what contributes to the total revenue based on the days since this first purchase so in total about $127 million were spent on day zero i.e the day of the first purchase and then after that it dropped significantly to like 31,000 51,000 and whatnot anyway with this total revenue i went and took it a step further and put it into a percentage and we can see that it goes from 61% to less than a percent i also plotted it for more of those visual type and so what we can extract out of this is that in general or on average a customer spends for the total revenue that it spends spends about 60% of it on the first day and then minimal after that so what we’ll do is go back in and adjust our query to take account for this and for a cohort year we’ll only look at the revenue for that cohort year if the purchase was completed on their first day and we won’t take into account anything else because the majority of purchases are done on the first day so how can we do this well conveniently in that view that we created we have not only the order date but also the first purchase date so we can use those two dates and match up where they’re equal to each other to get only get those purchases so i’ll put a wear statement in and we’ll set the order date equal to the first purchase date and that’s really all we have to do for this now pressing command enter we have some updated results and it looks like our customer revenue dropped a little slightly and plotting it we can see yeah it drops down slightly below 3,000 although it was before around 3,000 anyway the main thing here is now whenever i have this exponential trend line which i thought that you thought like with removing those previous years that had more spending actually it’s more pronounced that the future years such as 2022 and 2023 spend even less so this is a pretty big breakthrough that we’ve come to basically uncover in this and could lead to especially at the trend that we’re going at right now this could have serious implications on the business and would be a great insight to bring up to our superiors or to our stakeholders so that’s the end of what we’re doing for answering this question on analyzing customer groups as i feel like we’ve found a pretty significant insight with that what we’re going to be doing in the practice problems is actually going in and doing an analysis of the revenue and the total customer count but looking at it over time on a monthly basis to get to find out why do we have certain years lower than others and to uncover other insights that i’ll detail more in the beginning of the next video after you get done with those practice problems we’ll be jumping into installing vs code which we’re going to be using to document the insights for our project specifically in the next lesson we’re going to be documenting what we learned from this question specifically with that see you there welcome to this last lesson as we’re going through this chapter on an intro into our project specifically for this we’re going to be going through and setting up vs code now as a refresher on why we’re doing this and not using something like dbver dbaver is great at actually going through writing sql queries analyzing them and improving them but when it comes to actually sharing it and collaborating with others using things like github or even documentation tools like markdowns it gets quite hard so for both my workflow and kelly we like to use this in cooperation with vs code and this code editor is going to allow us to do two major things for this the first is we’ll be able to build a readme or a markdown file that will document all of the different analysis that we’ve done whenever we want to go and share this and the second it makes it super easy to push this up to github and share it with others to see the work from our readme or markdown file now if you take my basic sql tutorial you’d probably have vs code so you can skip that portion of the lesson but we will be going on to how to actually build out that readme specifically for question two which we answered in the last lesson but before we jump into that we’re going to quickly go over the analysis you did in the practice problems that we uncovered even further insights in the last lesson we went through and evaluated how do different customer groups generate revenue specifically we broke it down by cohort year and we found out what is the average customer revenue per cohort year at this macro level we were able to see some call out specifically that there’s a general trend going down for c uh per each customer revenue which is not good and so as our practice problem assigned you went further into analyzing why do we have these dips was there something deeper going on in the data set besides just customers spending less so to catch people up that didn’t do the practice problem we went through and analyzed customer revenue and total amount of customers on a monthly basis we got this final table which has that total revenue total customers and then the customer revenue let’s start with the customer revenue first because we’ve just been talking about that as we saw in that last lesson we saw that it’s slowly going down over time so analyzing at the monthly basis not really helping out that much now if we look at something like the total revenue and the total customers and we plot this we get something like this where the blue bars are the monthly revenue and the line chart here is the total number of customers so looking at general trends overall if we actually plot a line of best fit we would say or we would think that our revenue is going up over time or our net revenue is with the exception of a pretty big dip down in 2020 probably due to some sort of pandemic that happened during that time period and then it rose after that and then it was slightly less down in 2023 anyway the major insights that i think we are applicable to us from that last analysis is if you actually look at it how we said previously you know more customers equals more revenue it does match up but then when we get to 2022 and 2023 we can actually see that there’s pretty large gaps in between here there’s a lot of customers but the revenue is not matching which helps us explain even further what’s going on in this graph basically yeah we’re getting higher number of customers but customers are spending less anyway pretty interesting insight on this let’s get into installing vs code if you navigate over to the link on the screen you’ll get directed to the download page for visual studio code more recently microsoft has been advertising this with github copilot so it has this hey it’s redefined with ai and they’re really pushing that we’re not going to go too much into ai features we’re just going to be downloading this code editor you should download some sort of file click it get it launching and in the case of mac it unzips this file and it’s automatically the visual studio code app which i can just take and drag and put into my application folder so it’s in a much safer more secure location if you’re on a windows machine it’s going to walk you through an installer so quite a bit more steps but it’ll actually direct you on where you could actually put this vs code and if you want an icon anyway regardless you get a system message asking if you want to install this app that’s installed from the internet yeah you’re fine with it open it upon launch you’ll get this welcome message that will actually guide you through a step-by-step process that if you want to do you can do but we’ll be covering all the key features you need to know for this so don’t feel like you have to do this so let’s briefly explore visual studio code before we actually get into installing or setting up our projects folder that we’re working with over here on the lefth hand side is our activity bar and whenever we press our activity bar a sidebar slides in or out depending on if we want it there this first one’s an explorer we don’t have a folder open yet i’m just going to open a dummy folder you don’t have to need to do this and anytime you’re opening any of these it asks if you want to trust the authors i’m opening from my own computer i trust myself i think so at least anyway this basically shows a file breakdown of what’s inside of this folder and then folders themselves have these carrots that you can drop down or open if you want to see inside of it if i actually want to see these file locations you can just rightclick it and then on mac it’s reveal and finder on windows it’s going to be reveal and file explorer anyway you can see that the structure of this is the same as what we’re seeing over here in that file explorer all right other things in the activity bar we have a search functionality so if i want to search sql all the different occurrences will pop up here and i can go to it and it will take me right to it next is on source control which controls how we’re going to get this onto github we’ll be covering more of this and interactions with github near the last chapter or in the last chapter so don’t worry about this too much oh and i guess what i forgot to mention previously whenever this popped up over in this right hand side so if i’m to close this sidebar right here this is our code editor itself so if we actually open back up sorry and open that second query i’m going to close this now we can see i’m going to actually expand this by pressing command plus or control plus on a windows we can see that we have that sql query right inside there and if i needed to add anything like i did want to use an alias right here i could just type it in and then now we’re noticing that up here in the top there’s this white dot appearing that means it’s the ch we have changes this is not saved you can just save it by pressing command s or control s now what we’re going to be doing later on is actually going into the readme and building this readme out and what i really like about vs code is as you can see we have all this fancy dancy markdown language typed into here and if i wanted to see what it actually looks like with the readme selected i could select this right here and it allows me to preview the readme with all the different images and whatnot right next to it as i’m scrolling through so one of the main benefits why we’re using vs code all right i’m going to go ahead and close all this out also going to zoom back out so we can see everything um okay last two things they have a debug run and debug section we’re not going to be using that and then finally extensions it’s really popular if you’re using this for a particular programming language like python or whatnot to have the appropriate extension installed so in this case you install python to use python we’re recommen so overall there’s not a lot of extensions or really any that i think you need to install for this if you do want to install one just to see what it’s like i recommend this one on code spell checker when i click it it opens right up next door and if i want to install it i just click install it asks if i trust this publisher yes i do and now i have this code checker inside of here so if i actually went back to that sql file we had previously it will now go through and flag some of these keywords that don’t have an underscore and it calls it an unknown word you can actually go through and try to do a quick fix with it but those are the column values that came with the database so we’re not going to change them at all mainly i find it useful for if say i need to create a new alias and i’m going through it and i wanted to sum something like total customers and i assign the alias if i were to assign an alias with misspelling in it like this when butchering customers it’s actually going to call it out and so i know that i misspelled it there anyway that is extensions no i don’t want to save any of this the other two things in the activity bar to be aware of are your account right here and then any settings specifically what i find myself gravitating towards using a lot is this command pallet which has the shortcut of command shiftp or control shiftp that’s the one shortcut for vs code i would highly recommend having memorized when i do this this search bar comes up at the top and then i can search any type of settings i want to change in vs code so say i wanted to change the maybe the color theme of this i would type in something like color oh i can see that i have preferences color themes and then it allows me to go through a menu and select a host of different options in here the last thing to note is the status bar down at the bottom we won’t be using it too much like in our case right now i’m zoomed in and i could go back and reset it you’ll also have information down like the lefthand corner if we’re using git and then if there’s any issues going along with it let’s now get into setting our projects folder up that we’re going to be eventually pushing to github we’re going to be setting it up building out our readme and also adding all those sql files or the last sql file from the last lesson for this we want to open a folder that has our project in it but we need to create a folder if you will now back in dbe if you remember we created a project folder already and it has bookmarks dashboard diagram and even all of our scripts in it i’m not about reinventing the wheel i think we should just use this project right here as our project folder itself so we can do this a couple different ways i want to find the location of this so i’m going to rightclick it and i’m going to say hey show resources in explore now this is the projects folder i’m actually going to back back out just one location so that we can see okay so this is the folder itself of this intermediate sql project along with those folders underneath it i want the file path location to this specifically i want to go to this folder location when we go to open this in vs code so i’m going to open up a folder in vs code on macs unfortunately the folder location that this is within is hidden so i’m going to hit a shortcut of command shift period and i know in my uh home folder of luke baruse that it’s in the library folder and then from there i can navigate to the debaver specific folder going into my workspace i then see the project itself and then i can open it it’s going to ask if you trust the authors of this file in this folder i do i’m also going to just enable this to trust the files and all folders within here so now we have inside of our explorer right here we have a few different folders if you will i’ll be honest we’re not going to use any of these at all actually one thing to call out is you may visually only see the bookmarks diagram and scripts but then we also have these other they’re called dot files and once again if i press command shift period on this we can see these dot files they’re actually just hidden files i’m going to maintain them hidden by pressing command shift dot anyway key thing here is those folders and files aren’t important along with we can be selective on what we actually put into github so we will need to be because we don’t really want to put these up there anyway anyway let’s make our first file we come up here to the top and we select new file i’m going to give this the name of two i like to do two to basically designate hey this is the second question and call this cohort analysis.sql and as you notice as soon as i name that sql file i got this new icon right there that shows me it’s a sql file when i press enter it automatically opens in the text editor to the other hand side what i can do is now copy that query that we did previously then inside of vs code paste it all in i have this white dot saying that it’s not saved so i can press command s or control s and it’s now saved in there so i’m going to go ahead and just close this all out one thing to note inside of dber underneath that projects folder itself we’re not seeing any of the different files pop up like we just created that sql file that’s because we haven’t refreshed it if i actually rightclick select refresh the query now will appear inside of this project folder if you’re clicking refresh and it’s not refreshing or showing that i actually had to just restart db to get this to work so yeah just word of warning anyway this sql file is now here and so i’m actually going to close out this script and this one so if i wanted to i don’t necessarily have to go back into vs code if i want to edit it i could edit it from right here say in this case i call this ca and then i save this pressing command s whenever i come back in here and actually check this sql file i can see that the alias got added i don’t want it i’m going to add command s so let’s get into building our readme file as a reminder that’s going to be basically the front page of our project detailing all the different analysis we did breaking down each of the three questions that we’ve gone through or will go through now key things to note for github we want this file to be called readme.md and that’s because github will specifically pick up on this naming convention and then display this below here so we’ll get into creating a file i’ll call it readme and all caps locks then this icon changes to that readme icon and for the file it’s a markdown file so i’m going to give it m then go ahead and press enter and it’s open up right next to it first thing i’m going to do is just start by giving it a title remember we can do different headings depending on how many hashtags we have i’m going to give it this one of intermediate sql sales analysis but what the heck does this actually look like we can click this icon right here for it to appear right on that right hand side so as we go through and type different things we can see how it is actually formatted as we go through this now what sections are we going to be putting into this well really it’s up to you you don’t have to follow all or even any of the things that i’m going to put into here but i’m going to recommend these major sections first we’re going to have a short little overview then from there we’ll get into our three business questions just giving the short description and then from there getting into the analysis approach breaking down each one of those we’re going to be doing question two on the cohort analysis and i’m going to walk you through that shortly now below these three questions in the analysis approach i only included one example right here we’re going to have our ending which has things like our strategic recommendations what we got out of this and any technical details of what we actually used to build this so let’s start going through and filling this in we’re going to start with business questions here i’m going to put uh one two and then three for the second question we did a cohort analysis and with it we were asking how do different customer groups generate revenue now i’m not really liking how this is formatted so i’m going to use some extra markdown in here putting double asterisks before and after cover analysis and then it like bolds it makes it stand out more so now let’s go into filling in the analysis approach that second question i’m going to go ahead and just copy this one right here paste it below and we’re going to start going to for this i’m going to title this section cohort analysis next we need to put in an analysis approach that we actually used here so i put some short bullet points in here of how we track revenue and customer counts per cohort what is a cohort is that we’re grouping it by year of first purchase and we analyze customer retention at the cohort level the next thing i like to include is the query itself now you can go ahead instead of doing a link we’re going to go over link shortly you could put in a code block so i’m going to just do three back ticks in this case you can find it up here top of your keyboard anyway i could just copy this query right here and then put it into our readme and it’s displayed right here i could also format it as sql by putting sql after those ticks and then it’s getting colorcoded like this oh this is all smushed i’ll be honest i’m a fan of dry or do not repeat yourself we already have this code somewhere so i’m actually not going to put that right here instead what i want to do is put a link to this sql file and we can do this by putting square brackets and in square brackets is what the text is going to be i’m just going to name it the name of that file and then in parentheses is the actual file location on a mac i’m going to press backsplash i think windows you can press forward slash and then all the different things that i have access to are going to appear right here i’m going to select that first one of the sql file and then yeah now over here on the right hand side i can see whenever i click it oh the file itself actually pops up so i know the link is working properly and these links are also going to work on github when we get there all right next section i have are on visualizations and that’s if you’ve generated any images you don’t have to do this per se but in my case i really like doing this so what i’m going to do is i’m going to come over here and i’m going to create a new folder and call it images i like to organize all my images in one location so i’m going to take that image it’s on my desktop i’m going to drag it over into the folder itself it’s right here conveniently it’s just named image i’m actually going to change that by right-clicking it and selecting rename and call it this of two_cohort_analysis okay now going back into the readme itself the image name is just the alt text you can put with it mainly we need to be more uh pertinent about what the actual image name is once again i’m going to sl backslash and then from there i want to go into the images folder and i want to select two cohort analysis oh it’s popping up right next to it no i’m good after this we’re going to dive into key findings and i’m going to summarize this calling the main points that revenue per customer shows an alarming decreasing trend over time i call out specifically that 2022 and further years are just declining over time although net revenue is increasing is likely due to a larger customer base which we found out when we did deeper analysis and this finally brings us into the final section of what are the business insights and so for this i have the following that the value extracted from customers is decreasing over time and needs further investigation we need to find out what is the root cause of this in 2023 we also saw a drop in the number of customers and so we also saw a drop in revenue because of these two facts alone the company is facing a potential or actually what we saw in 2023 is seeing a revenue decline so overall this is a good step in the right direction on what we need to recommend on where we need to go all right it’s your turn to now go through and build out that readme document and hopefully you’ve been following along with installing vs code and whatnot we do have a few practice problems for you to go through and get more familiar with vs code if you want that practice along with we’re going to have that template for you available in order to build out this question number two all right in the next chapter we’re going to be getting into data cleaning my favorite part of data analysis so i’ll see you there welcome to this chapter on data cleaning and in this we have three lessons we’re going to be covering for this in the first two we’re going to be covering some core concepts you need to know about data cleaning specifically this lesson we’ll be going over conditional expressions for handling nulls things like coales and null if in the next lesson we’re going to be going over strings because from time to time you’re going to be dealing with strings and you’ll need to clean them up and maybe put them together or even separate them at the end of that lesson we’ll be applying all the concepts we’ve learned in order to further refine our view on cohort analysis finally in the third lesson of this chapter we’re going to be getting into answering question one from our project which focuses on customer segmentation now our project consists of three questions and in the previous chapter we focused on that second question on cohort analysis in this one we’re going to be using customer segmentation in order to find out who are our most valuable customers and we’re not only going to be using that cleaned up view of cohort analysis to help answer this but also some functions we learned earlier on statistics so we’re focused on two functions for this lesson and you may be like luke how the heck did you pick that out well if we go into the postgress documentation underneath the sql language we can see that underneath the functions and operators there’s a host of different ones that we’ve covered if you’ve covered along since the basics course we’ve covered and touched on a lot of these and we actually have covered on conditional expressions navigate under this we can see that for postgress there’s four main types and the main one is case which we covered back in basics but there’s two more that we need to cover around coales and null if now postgress has this one on greatest and least these functions have different capabilities depending on which database you’re working in also kelly and i don’t really use this this much so we’re not covering greatest and least anyway let’s get into how we can actually use coass and nullif in a very simple example you don’t have to follow along with this i’m just doing this for demo purposes so the easy way to demonstrate this is with a fake table i’m creating here i’m calling this a data jobs table it has three columns in it technically four i guess if you count the id and what does it contain well let’s just run this query to actually see we get this table and in it we have things like a job title a column on whether is it a real job and then a final column on salary notice inside of here that there’s some null values in here we’re going to be using coass and nullif in order to clean these values up depending on what we want so let’s say for this column on is real job we wanted to fill in null values specifically let’s just assume that the database administrator assumed that all null values were no but we needed to make it no well we can use the coales function and in this it returns the first non-null value from a list of expressions right now we’re just going to use one expression we’ll move on to two after this but we can provide a default value in this case of no and ultimately in our case this is going to be used to replace a null value with a default value so here is a query that returns back our original table let’s modify this to fill in null with no so i call that coales function for expression one i leave it as the column of is real job and then for the default value or the last one we’re just going to put in no let’s go ahead and run this bad boy oops forgot to put a comma run it again okay we can see now we have this column called coales after the function and it’s filled in yes no kind of a better practice would be to actually assign this an alias when done so that way we can actually see it and bam we have the updated column title now what’s going on here with that coales function where we have this second expression well let’s say we wanted to fill in this null value for salary but we didn’t want to use a default value we wanted to just fill it in with if it’s null maybe just put in something like the job title specifically depending on where it matches up you would fill it in for the appropriate row that it comes from let me demonstrate it okay so we’re going to use that coales function again we’re going to leave salary in there and then for the second column we’re going to specify job title i’m going to leave the default value blank for right now finally i’ll give it an alias of salary pressing command enter now whenever i run this i’m going to make this a little bit bigger says error colas types integer and character varying cannot be matched the problem is salary is an integer and job title is a string so anytime you’re using this to have a column replace other they have to be the same data type in this case we’d have to cast salary as a text or varcar in order for it to match that same one that is job titles now when i go ahead and run this it actually works below and we have in fact filled in the appropriate column from that job title into salary you could put a default value in here i’ll just name it default value but in our case when running it not going to come up so let’s reset this back so we can get into null if now with our original table back say we had a scenario where we knew certain values weren’t correct or we didn’t want them in there and we wanted to make them into a null and like in this column of is real job kind of isn’t really an answer maybe we want to now make this into something like null now with null if this returns null if two expressions are equal otherwise returns the first expression and this one’s even more simple in that it can have either expression one or expression two where they can be either columns or single values let’s jump into it so let’s say we wanted to replace this kind of with null we call our null if function is real job would be expression one and then expression two would be that kind of as usual i’m going to give this the alias of is real job okay let’s go ahead and run this okay we in fact replace that kind of with null now you don’t also have to just do a default value i could do like i said an expression so i could do another column so in this case i could do salary once again i got an error message and it revolves around having a mismatch between the data types i can just fix this by casting salary as a text running command enter and bam anyway the point null if right none of these comparing these as it goes through none of these match so it doesn’t convert any of the values to null this value was always null anyway let’s jump into some real bro practice problems now previously whenever we’ve been doing any of our analysis all of our customer keys have conveniently always had some sort of purchase associated with it what we’re going to demonstrate is that all the customers in that customer table don’t necessarily have an associated purchase with it and whenever we merge them together they can actually have non values or none values or null values now if we were to run an average to find out what is the average net revenue per customer whenever we just have these nine values they’re not going to be counted but say we do want to count them because hey they are customers and we want them to be zero instead that’s going to affect the average overall and we’ll actually get to demonstrating how much it’s going to change the average revenue per customer quite a bit now let’s get into combining our customer keys with net revenue to show those customers that don’t have any purchases previously we’ve gone through and in our sales table gone through and got the customer key um got the net revenue by multiplying quantity times net price times exchange rate then obviously we’re doing a aggregation and so we need to group by customer key now running this we have net revenue for all these different values in here if i try to filter to find any net revenues that are null if i go to run this we’ll see that down below there’s no values in there so we hadn’t been seeing this previously but what we can do is with all of these revenues that we have right here we could merge this onto our customers table and then this will expose customers that don’t have a net revenue so what i’m going to do is convert this into a cte use a width statement calls this sales data and then assign it in parenthesis as always i like to make sure that this works so i’m just going to select star from sales data and go ahead and run this yep working below now what we want to do is i’m actually going to go into kazo erd is take that customer table that we have here and merge onto it that sales table so we’re going to make the customer table our a table and then sales table our b table so what we want to do is using our customer table use a left join to join on our sales table so we’ll move the sales data down we’ll say that this is going to be the left join and we’ll give it the alias of s for the sales data and then for the from we’re going to be doing from customer with the alias of c let’s go ahead and just run this to see if it’s working and i got this error message saying syntax error at end of input basically i didn’t say where or on what we’re going to actually merge on specifically we’re going to be merging on the customer key of both of these different tables okay let’s try to run this now all right we have the customer keys and all the information from the customers table we don’t need all this information per se we just want to make sure we have all the customer keys along with all the different net revenues and as you can see there are now no values in here because there’s customers that don’t have net revenue so let’s modify what we’re actually bringing in here we’re bringing in from the customer table the customer key and then from that sales data uh cte above we’re bringing in net revenue running this boom simplified version of actually being able to view this so first let’s fill in these null values with a zero just to demonstrate it in a new column we’re going to call that coales function running that on net revenue and we want to place those nulls with a zero running command enter bam we got this over here so not bad now what we want to do is to show the difference between these we’re going to run an average on only net revenue and a average on the net revenue with zeros filled in so basically all customers i’m going to remove that customer key so that way we don’t have to do a we want to do an average on all of that so i’ll call the average function on that first column and an average on that other second column for zero filled in for the null values running this we can see that the averages are quite different right so the first one is around 4,000 and the second one is less than 2,000 now these names for columns aren’t that descriptive so i’m going to name the first one as spending customers average net revenue because they’ve spent money so that’s the only the customers that we use for this and the next one is all customers average net revenue now running it more descriptive titles for this and viewing it visually we can see that when we look at all customers the average net revenue is actually less now this was mainly done for demonstration purposes cuz there may be situations where you do want to consider all customers in our case we are going to just consider only the spending customers in our analysis and not necessarily all customers so that coales we’re not going to do a real world example of null if because it’s going to be frankly very similar except opposite if you will but what i have are practice problems for you to go through now and get familiar with both of these options in the next lesson we’re going to be jumping into understanding how and all the different functions for formatting strings so with that see you there and in this lesson we’re going to be going over further on data cleanup specifically around strings how to format them we’re going to be covering four key functions that i find myself using from time to time and then from there going into modifying our view that we created on cohort analysis specifically we have columns on a first name and last name we’re going to combine it into one let’s get into it now in the last section we were looking at function operators specifically going down here we were looking at conditional expressions in this one we’re going to be going back up into this section on string functions and operators now inside of here there’s a host of different functions and operators that we can use on strings and the first one we’re going to be jumping into is this one here on lower how to convert something to lowercase and with any of these functions they’re going to take string values so in that case i’m going to do that lower function and i’m just going to put a string in in there and we’ll just put my name in all uppercase we’ll go ahead and run this we can see it outputs it below in all lowercase if we have lower we probably also have something like upper running this we can see that it’s all upper this would usually in the case that you have some lowercase values in there and it would raise it all up if there were some lowercase values in there the next is the trim function we’re focus on the one up here this one down here is a non-standard syntax so we’re not going to use it and from this it relieves the longest string containing only characters and by default it’s a space let’s actually just look at this real quick to understand what’s going on so in the case of our example if we’re using this trim right now whenever i run this command enter there’s no really change in this whatsoever now let’s say that there was a space at the beginning and we’ll do a space at the end running command enter you can see that there’s no spaces when if we were to just run it without this trim function i’m going go ahead and actually just remove this running command enter we can see that it does in fact enter spaces in there even when i check it so using this function is very important especially whenever you’re working with databases with very dirty data and you need to remove any different spaces now let’s say that we had some symbols in there like we had dirty data and we had some symbols surrounding this that we wanted to actually remove in this case i have two amperands around each when i run this command enter we can see we have this but we want to remove that from here well going back to this definition of it we can specify whether we want to trim based on the leading trailing or both being the front or the back of a string and by default it does both is well both is the default then we can specify the character text which is what we want to remove and then from the string text so inside of here i could do something like both i want to remove that amperand sign and i remove it from this let’s go ahead and run this and it removes the both those amperands on the front and the back also i notice that my e is missing in here now going ahead and run it boom now that’s what we have so what we’re going to be cleaning up with this view well if we open it back up go into cohort analysis we can see underneath that data tab we specifically want to focus on this that given name and surname which will be like last name and first name anyway we want to combine these into just one column we don’t need them to be separated for our analysis now because of this we’re going to have to actually update our view for what we have currently now with this we’re going to be basically removing two columns and then adding a new column so because of this we can’t necessarily just run create or replace view since we’re altering columns we need to run like alter view but that’s even going to get complicated i’m going to recommend we just start over with this query and drop this view so i’m going to go ahead and go ahead and copy this command c and then in here i’m going to go ahead and paste it now remember we want to combine our given name and surname i’m actually going to just run this query to show what’s going on here press command enter i have this as in front of here that doesn’t need to be in front of here so i’ll move that up top run it again okay we have all of it as we saw before the given name and surname so we want to combine these two going back to the documentation on string functions operators scroll on down until we get to other string function operators they have on here the concat function this concatenates the text representations of all the arguments null arguments are ignored so for given name and surname what we can use is this with the concat function specifically i’ll type out concat open and closing parenthesis around here so we have the given name and surname and we’ll name this as the clean name okay let’s go ahead and run this and now we can see the names are now combined okay not too bad now one thing to note is well we need spaces in here and sometimes i find especially with text columns there may be extra spaces in here so one let’s just add that space i’m talking about i’ll do a i’ll do a single quote space single quote and then comma run command enter and now we can see that that there’s a space in between here but like i said sometimes the names may have spaces around them so just as good measure i’m going to put trim around both the given name and around the surname okay running this pressing command enter we now have all the values cleaned up in here and we did some protection so now we need to actually update this cohort analysis where if we went to look at it remember if we just tried to run this right now so create a replace view as the cohort analysis pressing command enter i’m not going to get it because of the column issues that we addressed before so we need to actually just drop this database or drop this view first so we’re going to call that drop view on cohort analysis and then run everything underneath it i’m going to run this all by pressing option x and looks like two queries are done as always i’m going to just close out of this to make sure i have the most upto-date one click inside of here press f5 to refresh and open up cohort analysis scrolling all over we can see we have now that clean named inside of here so our view is good to go now for the project all right you got some practice problems now go through and get more familiar with these text formatting functions in the next lesson we’re going to be jumping to another question for a project on customer segmentation looking forward to it see you there welcome to this third and final lesson in this chapter on data cleaning and for this we’re going to be focusing on question one for a project specifically this is going to build further on analysis we actually did earlier with segmenting customers and some discussions on customer segmentation specifically we’re trying to find out who are our most valuable customers for this we’re going to be breaking up our customer into tiers using percentiles into highv value midvalue and lowv valueue customers now this is a very typical business process that you would find yourself doing in order to target certain customers and then distribute marketing that fits their need and so shout out to kelly for coming up with this example because i feel it’s a really good demonstration of what you find yourself be doing as a data analyst as always i like to start with what is the final data set we’ll be getting for this and so we’ll be calculating or actually finding out based on customer key and that clean name that we did in this chapter to determine what is their total ltv lifetime value or their if you will net revenue and then based on these values we’re going to use percentiles to categorize customers in either to low value midvalue or high value we’ll also take this calculation a step further and also dive into analyzing not only just having those names that way marketing can target these customers but also actually understand these values such what are the percentages of these different segments how much they’re contributing and whatnot so let’s start a new sql script documenting this analysis similar before we had a our own script for sql here i’ll go ahead and we’ll start a new sql script then i’m going to go up here and then rename this we’ll name this to one_c customer segmentation.sql okay this should be good all right now one thing to note this is going to be inside of our scripts folder but we don’t necessarily want it here if i rightclick this and then go into show resources in explore underneath scripts i can see it’s right here and i actually want it higher up so i’m going to move it out if you’re on windows you do something similar with your file explorer and then down here it’s not actually showing up i can press function f5 and that sql script disappeared but now i’m actually seeing this one and also readme is popping up now i guess i didn’t uh refresh as well anyway i can now open this back up this is what the sql file is we want to work with so first three columns of interest that we want to get into here so we want that customer key we also want that cleaned name and then from there we want the revenue for each of these customers or that total lifetime value so we use a sum of total net revenue and we’ll assign this as total ltv just as a reminder going back to that cohort analysis we could have multiple entries in here like 180 did multiple purchases on different days and we had that in a total net revenue so that’s why we’re renaming this new column total ltv because now with 180 we’ll have the total lifetime value we want this from our view of that cohort analysis and we’re doing a um aggregation so we need to do a group by using the customer key and then also clean name so let’s go ahead and run this and see what we have i have no active connection so if there was a reminder if you’re already connected reconnect to your database and i just need to reselect it up here now everything’s looking good let’s try to run this again all right bam this is what we want clean name customer key and then the total ltv for each of these i can even i can even do the order by descending or actually i want to do order by ascending and see that hey okay 180 is now combined into one looking good now that we have this total ltv we can now bucket these customers into high value low value and what’s the other one midvalue now we’re going to be doing this on percentiles using the 25th percentile and 75th percentile so because we’re using or running a percentile on this aggregation right here i’m going to put this into a cte we’ll call this customer ltv and we’ll put this in parenthesis from there on this ct we’re going to run that percentile continuous function remember we’re doing the 25th and the 75th percentile basically everything between the 25th and 75th percentile is our midle so i’ll do 0.25 and then we’ll do the nomenclature of within group because we want to group it by a certain thing and we need to order the ltv or the total ld ltv column to make sure we’re pulling out the correct um ltv as we go through and sort this and then we’ll give this the alias of just ltv 25th percentile let’s go ahead and just make sure this is right so i’m going to do a from the customer ltv pressing command enter boom okay 25th percentiles at 843 i did this already i know that this is actually correct so let’s now get the 75th percentile i’m going to go ahead and just copy this all because it’s just going to take some changing to do to it and then putting it inside of here changing that two in multiple locations to a seven and then running this bad boy boom so just so you understand what’s going on here those that spend around $843 are at the 24 25th percentile and so if you spend less than this you’re less than the 25th percentile whereas the 75th percentile those are around spending around $5,500 if you spend more than this you’re greater than the 75th percentile these will be our high value customers and those less than 25 will be our low value now what we can do is let’s just go back and i’m going to run just this query up here now what we can do because we have those percentiles we can use this basically customer ltv cte and we’re going to convert this percentiles one into a cte as well we can categorize or bucket them using a case when statement of whether they’re high value or low value or mid-value so we’re going to be making this into a ct i’m going to tab this over put a comma and we’re going to name this customer segments and then as once again opening and closing parenthesis so that way this is in a in a cte from this we’re going to select and i want all the customers from customer ltv so i’m going to do a um we’re going to give it the alias of c so i’m going do c.star and i’m going to go ahead and just put this down here of from customer ltv and like i said that’s going to be of the alias c and it’ll clear that little syntax error let’s actually just make sure that everything’s appearing right down here i have a comma after this so i need to remove that it’s appearing down here now we need to go through and now make that case when to basically bucket all of these into their different tiers gonna move this down some so it stops uh so it stops cutting it off okay we’re going to do a case and then we’ll do when and the first one i want to categorize is everything less than 25% as low value so when total ltv is less than this ltv 25 percentile which i’m realizing now we haven’t imported in now we don’t necessarily need to do a join with this what i can do is a comma because we’re not join it to the data i can just list it of customer segments and give it the alias of cs so now that’s available we can say cs.ltv 25th percentile then we want to assign it the low value we’re going to do one tac low value we stick a 1 2 3 at the front just to make the easier if we want to ever sort it um if you just do low value only and then try to like sort by the name alphabetically it like throws a fit mainly meaning you can’t sort it like that anyway let’s go into the next one and i’m just going to copy this because a lot of this can be repetitive and for this one we want to get everything that’s midvalue so everything that is less than or equal to the 75th percentile so that mid-range is going to cap encapsulate everything that’s equal to the 25th percentile up to the 75th percentile and equal to it and then i’ll change this to two mid value now since we got everything underneath the 75th percentile we can now categorize everything else as high value all right let’s go ahead i’m going to remove this space here let’s go ahead and run this and fingers crossed i see my issue i have a syntax error at or near when and that’s because i don’t have a comma after here also i never gave this alias or this case statement a name specifically we want to name this customer segment all right let’s go ahead and run this bad boy okay it’s working now let’s make sure that these are categorizing correctly if i remember previously i’m actually going to just select this one time and press command enter oh and i realize now it’s uh not going to let me do it like this unfortunately i’m going to just copy this go into a new script because i want to actually show this then paste this bad boy in and run this and i’m silly i need the other ct anyway you don’t have to do this main purpose of this is just to see what these numbers are remember it was 843 for the 25th percentile and 5,500 for the 75th percentile now running this complete one are these numbers making sense yeah because 5500 should be the high value it’s greater than that for this second entry and then looking at these these fall in between yeah it looks overall let’s look for a low value okay we got a low value down here of $23 falling in okay data looks like it’s calculating correctly all right so this table right here would be great to now export and send to our business colleagues to basically find those people that we want to target i don’t know why this window is so wide like this um but on mac let me know if you’re having these same problems it shouldn’t be this big anyway i’m not going to do this right now but this would be great to send to business colleagues and for them to actually now send targeted campaigns to these individual items depending on what our strategy is and how they are segmented but let’s dive a little bit further first to analyze how much do these different customer segments how much um how much are they contributing what is their customer revenue and also not only what is individual and average customer spending but also what is their total revenue so what i’ll do is i’ll now convert this into a ct as well cts on cte on cte i’ll give this the name of segment values and then as and then once again open and closing parenthesis with this we’re going to just go first and get the customer segments and mainly that customer segment column i mean and we’re just going to get this first from that new cte of segment values okay let’s make sure that this is just working correctly and we can see it’s doing this all down here so the first thing i’m going to do is get a sum of all the different revenues so we’ll run sum on total ltv and we’ll name this conveniently total ltv because we’re doing a summation we also need to do a group by on that customer segment all right we’ll go ahead and run this all right not too bad so this is telling us the total amount and our high value is at 135 million whereas our low value customers have only contributed 4 million if we plotted this on a pie chart to see how much they actually contributed part i only recommend pie charts if it’s three or less values we can see that low value is oh my gosh we got to do something here and target these lowv value customers better so this is great the analysis that we found out of this midvalue is around 33% which you would expect it to be about a third and then the high value is almost 2/3 so that’s pretty i mean really high for high value so based on just this little data piece alone this is evidence enough that we need to do some different marketing strategies especially with our lowv value customers now because we put those numbers in the front of this customer segment if we wanted to we could also do an order by and we could do that on customer segment and we could put it in descending order running this we’re now getting those high value up top mid value low so that’s why we put those numbers in the front for those columns so we can sort it more easily anyway let’s calculate a couple other things mainly i want to find out what are the number of customers in each one of these segments so that way we can then go through and find out what is the basically average ltv or lifetime value for a customer in a certain segment so getting the count first we’re going to be using the customer key for this we’ll assign this as customer count running this we got the counts and as expected one and three should be equal because there’s 25% in this 25% of that and then this one right here should equal the basically double of these um because it’s the 50th uh it’s 50 percentile or 50% in between so now that we have this total ltv and this customer account we can divide these to get the average customer value so i’m just going to take this and then divide it by this value right here and this will be our average ltv bam all right now i’m going to close out of this right here so this is pretty interesting our highv value customers are submitting or submitting on average around $11,000 whereas our low value are only around $350 pretty substantive probably why those low values only contributed around 2 or 3% of that total revenue now there’s a host of different marketing strategies you could go about doing this you can feel free to pause the screen and look at into each one of these of what you could go for doing this isn’t necessarily a master class on marketing strategies it’s on data analytics we’re not going to spend too much time on this but i did want you to understand what are some different capabilities we can do with this powerful data now there’s no practice problems for this lesson but i do expect you to go through and update your project readme specifically i added a little description of what we’re doing for all the different segments i added a link to our sql script along with that visualization that i showed you earlier breaking down those things because that was the key insight we got from this i broke down the statistics talking about the highv value midvalue and low value segments how much they contribute of each and what their contribution of revenue is and the big disparity there and then i wrapped it up with business insights what could we potentially do to target highv value midvalue and low value customers all right it’s your turn now to go through and update all that we’re jumping into the next chapter in query optimization where we’ll not only go query optimization but also answering our third and final project question see you there welcome to this chapter on query optimization for this we have three lessons we’re going to be going to the first two are going to be focused on understanding how to use the explained keyword along with some query optimization basics the second one’s going to jump into more intermediate and advanced ones and then finally in the third lesson we’re going to wrap it all up with our final problem for our project now in this video in the next one we’re going to be going over query optimization techniques and i have a list here of beginner intermediate and advanced techniques you should be familiar already with beginner ones but we will do a refresh during this video and then in the next one and the next lesson we’ll be jumping into that intermediate and advanced and this will all be done while using explain and analyze to break each one of these down now for the third lesson it’s conveniently on the third question or the last question in our project specifically we’re going to be doing retention analysis analyzing who hasn’t purchased recently we’re going to get a visualization similar to this and wherever we break it down by the different cohorts years and see how many customers are active and how many are turnurned or didn’t purchase something recently this is a super common business concept to understand and coincidentally kelly was just telling me that she actually was implementing it in her job today so let’s get into breaking this down we’re going to be using these keywords of explain and explain analyze for each of these they just go at the beginning of a sql command whether what you’re using but what’s the difference between these two well explain demonstrates the execution plan without actually executing it whereas explain analyze basically means like it’s going to analyze it and it actually does execute it so we understand what the execution times are so say we have this simple query of select star from sales i could use explain at the beginning of this running command and enter and it’s going to tell me the query plan i’ll break this down in a second now we also could use something like explain analyze right and remember this one is one row when i run explain analyze we have two more rows mainly this one has the execution time it has well not only the planning time but also execution time so you may be like luke when the heck would i use explain and when would i use explain analyze like why would i want this if this doesn’t even tell me the execution time well let’s say you’re working with an extremely large database like millions or even billions of rows it could be extremely cumbersome to run this query and cost a lot of money not only time but also money so there may be cases that we would only want to use explain but since this database we’re working with is so small we’re going to always be running explain analyze with all the queries we do that way we can also see the execution time so let’s break this down on what this is actually providing so this first row here says that it does a sec scan which means it does a sequential scan basically going row by row by row and it specifies that it’s doing this on the sales then from there we have three variables inside of parentheses here cost is just an arbitrary unit and that’s just assigned by postgress if you want to be real about it it’s just made up but quantitywise it remains consistent the one thing to remember is that these numbers just because say you have a cost of 500 and then another one you have a cost of a,000 the query is not going to necessarily take double the time it’s just going to take longer anyway with this cost you can see it has the syntax of this starting value then this dot dot dot and then the next value after this this is the start cost and then this is the final cost so ultimately this query cost in this case that is shown in demo 18.5 next are the rows and so that’s the estimated number of rows and then finally the width is basically still that row size but what it is in bytes going back to our original query we can see that we have a cost a final cost of 4500 there’s almost 200,000 rows and the width is 68 bytes ultimately this took this query took 30 milliseconds to run and the planning time or what it was going to do whenever it was planning on how to execute this query took less than a millisecond now all the times with dealing with all of this are going to be in milliseconds so you may be like luke what does this even matter like we’re talking about 30 like half a second well once again this is going to come into play whenever you’re dealing with databases that are millions and billions of rows those milliseconds aren’t going to be that anymore and i’ve had queries run as long as an hour so query optimization is a must for you to understand now expand this out we can actually see there’s some other things as well to cover here specifically going along with that execution time we have the actual time the rows and then loops rows remain the same in this case loops is a more complicated topic and really relies on if we’re basically performance and sort of recurrent loops especially whenever we do joins we’re not going to worry about that too much but what i do want to focus on is this actual time right here and this tells us that hey we started this query at 017 milliseconds and it ended at 14.8 milliseconds and then the time after this of the execution was the time it took to display it and do all that now it’s important to understand that with explain whenever i run this one it does not have that extra parameter over there as well i didn’t have it uh pulled out at the moment but we still have that same thing of cost rows and width okay so let’s build on this further by calculating the net revenue per customer and seeing how this query plan changes for this we’ll say we need that customer key and then like usual we’re going to be doing a sum and this will be summing up the quantity times net price times the exchange rate and we’ll give it the alias of net revenue okay let’s go ahead and run this bad boy and i got ahead of myself we got to do a group by anytime we do an aggregation so i’ll be specifying that customer key and then running this okay now with this what’s going on here is there’s actually two steps here each of the steps are denoted by this basically this arrow right here so this right here is a step and then this up here these three rows are now a step the first step would sort of counterintuitive but that first step is that sequential scan on sales it’s the most indented one in the fact that we’re doing the scan on the sales table getting all the rows we needed of 199,000 and we can see that that took 9 milliseconds to do then the next step goes into here performing the hash aggregate basically it does a hashing system in order to perform the aggregation we’re not going to go into hashing right now the important thing is understand that we are doing a sum function which is an aggregation it tells us it takes from 54 to 56 milliseconds so about 2 milliseconds to do this and this is done on only 49,000 rows and that’s because that group by or that customer key condenses it down the amount of rows under this it has other other information like group key and then also how much memory was used ultimately this query ended up taking slightly longer than we did previously now we’re up to 57 milliseconds total i’m going to add just one more thing to this and let’s add a filter to it and we’ll say we want orders only from 2024 so we’ll say that it’s greater than or equal to 2024 january 1st okay let’s go ahead and run this and we got an error for this why do we get an error right here well it’s because i have it out of order and that’s because even in the execution aspect we’re going to filter our sales table by that in 2024 and then perform our group by and aggregation and we can actually prove this by our execution plan in the fact that in our first step right here our sequential st scan it actually goes through and filters by those dates so that are in uh 2024 then after this which after we filter it for 2024 we can see that we have down to 10,000 rows then it sends it into our aggregate to do the group y and our sum and this takes 27 to 28 so this is like well even less than a millisecond and ultimately because now we do this wear clause we have a much shorter execution time so not only are we learning about how to read query optimization we’re understanding why do we have the order of these keywords such as where and group eye anyway it’s important to note that we’ve been using explain and explain analyze but over here on dbver they have an explain execution plan now if i try to run this with this explain analyze up here and click this and click okay it’s going to give me an error because we already have explain in there so it’s important that you select what you want to use and then use the explain execution plan or the shortcut of command shift e now this is going to pop up and asking what you want to do if you don’t want to do the explain analyze you want to leave that unclked i usually just maintain all of these clicked including the analyze and then from here click okay this i find is slightly less descriptive but it is more ordered in the information that it provides it’s still pro uh still in that same order of sequential scan is the first step and then the aggregate is next starting at the bottom going up but as far as the times and every and the cost they’re actually more in a readable format than that execution plan anyway is available if you want to use that way we’re going to compl continue to use explain analyze throughout the reigning of this video and the next video cuz i find that post useful last thing note is if you encounter any keywords you don’t know the best thing to do is just go ahead and copy this all and go into your favorite chatbot just paste it in and have it go through and actually explain what’s going on here step by step by step so in the remainder of this video we’re going to be going over some beginner optimization techniques that we’ve touched on briefly throughout this course but actually using explain analyze to prove why you should be doing these in the next lesson we’re going to go into more intermediate and also briefly cover some advanced techniques in order to further level up your optimization skills for this one on basics we’re going to be covering three ones and we’re going to be going over examples on the first two on why we use select star why we use limit and then for the third one we’re just going to just briefly discuss of using where instead of having we’ll start with the easiest one to actually prove it’s efficient and that’s using limit if i just run select star from sales on the entire sales table running command enter it’s taking around 18 seconds and what what you will notice for this i’m going to run this a few times the time actually jumps around so on average it looks like it’s around i don’t know around 24 or so anyway i have this in a not not optimized sql query i’m going to come over here to the optimized query so we can compare them before and after and we’ll put a limit statement we’ll just say we want 10 and this bad boy we get it in 03 milliseconds run this a few times yeah it’s maintained pretty consistent around 03 compared to our previous of almost 21 so there’s your actual proof that those limit statements are very helpful in minimizing the amount of data and saving you time next is on select star you’ve heard me time and time again saying “hey i don’t recommend using select star to select all the columns of the table.” so let’s try to optimize this and you know what i’m just going to list one column and that’s it customer key whenever i run this we can see actually i need to run a few times we can see that it’s over 30 seconds whereas the not optimized one whenever i’m running this one it’s less than 30 seconds what the heck’s going on here well in some cases like this one postgress makes it super efficient for them to retrieve data using this select star nomenclature and so yeah it is more efficient in some cases to use select star but i’m still sticking with it in the fact that i do recommend especially when you get into bigger databases millions and billions of row i would still stick with only listing one or however many columns you need for your analysis and not using select star now the last one to look at is using where instead of having and unfortunately you may not always have control over just easily switching from where instead of having so let’s say we have this query here where we’re actually getting the customer keys along with all their net revenue for it now if we wanted to filter this data based on the net revenue and maybe get some that are higher than or less than a certain value we would use a having clause in this case and we say hey we want that having greater than 100 or greater than a thousand and if we remember from order of operations that we first do that sequential scan so we get all 199,000 rows then when we’re doing the aggregate we then are doing the filter in this step with that 199,000 rows now we’re moving back to that original query to demonstrate this now with a wear clause unfortunately the having benefit is using it in aggregation but we may have a case where okay we can alter this instead to have it to where we want to get customer keys that are we’ll say less than 100 so not using that aggregation but more posts on a customer key anyway with this one the main point is that the filtering is done in that sequential scan out in the beginning and as we can see from this because it limits with how many rows are done our execution time is a lot shorter now you may be like luke you’re using where with a customer key of less than 100 and you’re using having the aggregation that we did of greater than a thousand yes i know these aren’t necessarily comparable but there may be a situation where yeah you know you want these net revenues a certain value and thus you want the maybe the order keys of a certain thing and you could then filter instead by the certain order key values or specifically not order keys sorry customer keys mainly what i’m getting at is if you have a choice that you could potentially modify to do where instead you need to take advantage of it all right you now have some practice problems to go through and get more familiar with using explain explain analyze explain feature inside of dbver along with testing out some of those basic techniques that we just went over the next lesson we’re going to be going over some intermediate and also advanced techniques along with a real world price problem all right with that see you there welcome to this lesson on optimization techniques we’re going to be starting by jumping back up where we picked off last and jumping into intermediate intermediate techniques we also briefly cover advanced techniques but overall they’re going to be outside the scope of this course and you’ll see why then at the end of this we’re going to be going into optimizing our query that we built in the last chapter on data cleaning basically applying all these techniques we’ve learned into how we can make a query run faster so what are we going to be covering for these intermediate techniques well we have four ones to cover but the first one we’ve really been covering in the last lesson and in this lesson of using query execution plans basically using that analyze basically using things like explain explain analyze or even dbver’s built-in options now we’re going to be going over three other scenarios besides this on minimizing group buy reducing joins when possible and optimizing order buys so let’s say we have this query here where we’re going through and getting things like the customer key order date order key line number and then also getting an aggregation of the net revenue which i need to add an alias of net revenue okay let’s go ahead and run this just to see what’s going on anyway we can see from this that well it’s two main steps of doing a sequential sand and then actually aggregating with our group five but our execution time even running this a few times is pretty high up there i mean sometimes getting as much as 100 milliseconds once again we’re dealing with milliseconds but if you have databases that have millions and billions of rows this can easily turn from milliseconds to seconds soon as those queries get longer than something like one or two seconds they get annoying af anyway with this query itself i’m just going to select it and run it we may not necessarily need to find out every individual line number and so if we were to go ahead and remove something like n line number in our case i’m going to go ahead and move it over to this optimize area and then take it out here along with taking it out here and then running this oops got a little bit of typo try again okay we can see that now we have a much lower execution time here at 67 seconds but consistently less than 100 that was just by removing one group buy so an important concept to understand is it really necessary to do all those group buys it can get costly over time and in this case we’re almost saving half the time if you will just by removing one group by next concept to get into is minimizing the number and also types of joins if you will on when we’re doing a query in this case let’s say we’re pulling in multiple tables into our sales table we’re also pulling customer product and date table i’ll go ahead and just run just the query itself and we can see we have yeah a lot of information in here now running this full query to actually run the explain analyze we can see that this query takes over 100 seconds running this query a few times we can see it runs around h around 80 milliseconds anyway pretty intensive anyway if we go back to that original query in this case we can see that we’re pulling in the year from the date uh table what happens if we remove this interjoin and just added in a way to extract out the year out of the order date so i’m going to go ahead and just copy this all paste this into the optimized i went ahead and already moved the inner join down here and then we’re going to just write an extract function using year from s.order date and we’ll give this the alias of year okay and we can clearly see whenever we run this this is providing us the exact same information of that year running the query completely now i need to move it up some running this one we can see well it’s looked like it’s maintained around 70 so the other one i already forgot what it was running around it’s running around 80 or so 80 or 90 so this one is i mean almost we’re getting a 10% gain or increase in performance just by removing an inner join and instead doing a function instead now it’s also important to note that establish the number of joins but also the type of joints and we’ll get into that with the practice problem coming up in a little bit last major concept to cover is optimizing your order buys sometimes order buys are not something you can just like negate but if you can they will save you some times specifically here well let’s just go ahead and print out this query pressing command enter i’m getting the customer key order date order key and net revenue and in our order by we can see we order by our net revenue first followed by customer key then the order date and then the order key rarely do i find ordering by all columns is really necessary anyway there’s a few different ways we can optimize our order by the first one the easiest is just limiting the number of columns in order by the second is avoid sorting on computer columns or function calls the third probably the most intuitive is place the most selective columns first in the order by basically if it’s doing something that’s going to filter out other rows you’d want to use this one first and then finally use index columns for sorting to leverage existing database indexes unfortunately we don’t have control over indexes indexing usually a database administrator does but if you did you’d want to use it in that case anyway let’s go with one of the recommendations of removing function calls so we’re going to go ahead we have explain analyze up at the top i’m going to run it and i’m seeing it around 90 milliseconds or so now i’m going to take this exact query put it over here and we’re going to remove that well the net revenue the aggregation up here on the sum let’s go ahead and run this and this one i’m seeing a lot less usually around the 70 to 80 millisecond range so we just cut off about 10 to 20% doing that alone now maybe we find out even more that we can remove the order by let’s say we want to just remove all the way to the customer key itself and then run it in this case i’m not finding that much of a difference even seeing it get as high as 90 so i’m not finding that this one is as great as the aggregation but overall we can see that it does have an appreciable impact compared to our notoptimized query so let’s get into optimizing our view that we’ve previously worked with and that was with cohort analysis we can go into it under databases right underneath our data set underneath schema public and then our views ourselves that cohort analysis now we can actually look at the query itself going under source and we have it all here i’m actually going to go ahead and just copy this bad boy and put it into this script here on not optimized i don’t actually create or replace any view so i’m going to actually remove this and instead put up at the top of explain analyze so i’m not liking how this is formatted so i’m going to highlight it all go to format and go to format sql and it’s going to break everything out more of like how i like it now let’s go ahead and run this explain analyze on here to see what we’re working with for our current execution time um and i have a typo because i didn’t get rid of this as in the front of here going to go ahead and run again okay boom we have this all and wow there’s a pretty hefty query plan and we can see this is some of our highest execution times that we’ve seen so far around 200 milliseconds to get this bad boy done it looks like it has a total of 1 2 3 4 five six different steps and that looks about right with the ctes and all the different group eyes we have in here now recalling back to what we just previously covered of how we can improve a query just looking at this we can see that the cte well it has a a bunch of group eyes also has a join so that may be able to be optimized and then we look down here to this bottom one this bottom or the main query itself and there’s not a lot of different techniques that i feel i can put into this as this is just doing a simple select and then from so primarily we’re going to be focusing on inside of the ct of customer revenue and the first one we’re going to focus on is the join now previously we discussed about minimizing joins but actually which is also just important is understanding when you should be using what type of join now a lot of our course and the previous course used either left joins or inner joins with left joins they’re specifically used in the case of for table a you want to keep all values in it and if there were maybe some null values that matched up with from the b table for the a table you would want those null values to fill in for a so we didn’t remove any of the a well if we knew what we were matching on had all contents from both the a table and the b table thus there are no nulls inner join is slightly more efficient to use because we no longer have to do this null check before actually joining so what i’m going to do is i’m going to copy this query and put it over into the optimize section and i’m going to change this here from left to inner the first thing i want to show though is the actual query itself the output pressing command enter what i can do down here is i can i want to see the total row count so i click this okay that’s around 83,099 if i go back to our one with a left joint i hope that whenever we run this query i’m going to select it all and then press command enter we can see for this one the row count is 83,999 so the same so they’re still doing the same thing where this one has a left join and this one has an inner join so now the question is is the explain analyze whenever we run this on the nonoptimize and on the optimize is it going to be quicker well for the not optimize or with that left join it’s around 200 milliseconds and that of optimize is well around the same thing around 200 milliseconds so although it didn’t work in this case to further optimize our query and just works out to basically break even there are cases where using an inner join instead of left join when appropriate can save you potential time in your query execution all right so we talked about joins the other last thing that we can do in order to optimize this query is has to do with this group by look at this we have a bunch of group eyes and when we actually look at it based on what we’re aggregating by we’re having a lot of repeating values and country full age given name and surname what do we mean by this well let’s actually look at the query itself for customer say 180 yes the order date is going to change yes the total net revenue number of orders but as far as things like their country full the age their clean name their first purchase date or even the cohort year that’s not going to change so why are we doing a group by on things that aren’t going to necessarily change we really care about just grouping it by the customer key and then also the order date so what we can do for this is like we said we want to minimize those group by but this query is not going to work if we go to run it right now it’s not going to work anymore what we can do is we can do an aggregation function with this we just need the max value from each of these or you could do min whatever not it’s very popular just to do max and i’m doing this for age the given name and then the surname with this it’s also important that you give it back its alias so i’ll be giving it for country full age given name and also surname so first let’s go ahead and just run this query and make sure that it’s working properly scrolling on over here we can see that everything’s remained the same for the country full the age and then also the given name or that that final clean name that we got to i think i called out first purchase year and cohort year when i first talked about this they didn’t have anything to do with the group by they’re done lower below anyway let’s go ahead now and run this query see how long it takes and with this one we can actually see that we’ve now got the execution time down to 160 milliseconds where previously it was around that 200 milliseconds so now that we have this optimized query that’s taking less time we can go ahead and update our view and we’ll be using that create or replace view cohort analysis as so we’re not changing any columns with this so technically this should work without doing a drop i’ll go ahead and run this it’s now telling me that it’s changing data type so in fact we do need to delete it or drop the view first of cohort analysis we’re going to now just go ahead and execute the entire sql script said it ran both the queries come over here press f5 to make sure that we have it refreshed open up cohort analysis and i can see that we have those max values and we’ve minimized that group by along with changing our join and it looks like it actually saved it to a simpler join now now that we were using that inner join to just join alone which that’s the default so makes sense now the last last thing to cover are these advanced optimization techniques we’re not going to be walking through any of these but they are ones that you should be aware of specifically they have these three major ones of using proper data types so basically not referencing data uh integers or numbers over something like a string using indexing in order to speed up your queries so basically relying on certain columns with indexes built in to sort them more quickly and then for large tables you can have partitioning built into them to per uh improve their performance now all three of these are controlled by database administrators specifically they control the data types they control whether columns have indexes and they control how data is partitioned so we’re not going to go into this because it’s going to be really specific on whether your database administrator has done this now if you ever run into a situation where you’re finding queries are running excessively long and you plug into chat gbt and you can’t find any results except for this around indexing or partitioning or data types this is when you’re going to have to go to your database administrator and ask them to make changes to your table that way you can get more efficient queries hopefully you have a good database administrator i have in the past and been able to go directly to them and get what i needed out of it and saved me a lot of time in the long run all right you have some practice problems to now go through and get more familiar with those intermediate techniques and optimizing your query along with using explain and analyze again all right with that i’ll see you in the next one where we’re getting into our third and final problem in this project see you there welcome to this last lesson in the chapter and for this we’re going to be tackling our third and final question looking into performing retention analysis specifically we’re going to be looking at who hasn’t purchased recently we’re going to use terms such as active and turned customers we’re going to look at it totally overall and then from there actually break it down into the different cohort years to see how it’s actually trending over the years as we have these different cohorts so we’re trying to identify which customers haven’t purchased recently and the technical business terms for this would be we’re trying to act identify active verse churned customers for us active will be those that have made purchases within the last 6 months whereas churned are those that haven’t made a purchase in over 6 months now 6 months isn’t necessarily something you’re always going to use as the hard and fast to delineate between active insurance it’s really going to depend on your industry and maybe even other factors as a general rule of thumb i have these four different areas and contazo falls into an e-commerce and typically we’d see them use a 6 to 12 month period since last purchase for this whereas something like a mobile app is going to be much more quicker with turnover so they’re going to have a 7 to 30 day since last session to identify active verse churned customers and now you may be wondering why the heck this even matters well we can send off this data that we end up calculating on finding out if a customer is active or churned and we can do specific targeting marketing campaigns in order to get them to re-engage also when we look at this holistically towards the end to get these like percentages per cohorts and stuff we can understand maybe the effectiveness of previous campaigns that we’ve used in maintaining activeness and preventing churn overall this deals with tracking our customer retention and also engagement which is necessary because we know we have customers that have bought from us before and they’re likely to do it again so we need to take use of that so what are we going to be working towards well we want to basically build this table here which is going to have information like our customer key and our clean name along with calculating things like when was their last purchase date and ultimately was this in the last 6 months and then classifying this as either churned or active to make this easier we’re going to be using the view that we’ve been using of cohort analysis because this has all the information that we need from it in order to extract out this information now like our last two problems i want to be working in a script that we’re going to be saving as our final script to upload into our project we put on to github right now we have our um one and also question two what i’m going to go ahead is go to vs code and then inside of here i want to create a third file and i’m going to name this retention analysis remember this is a sql file so i do dossql and then click enter we’re not going to edit it inside of here i just want to actually create it and then now going back inside of dbever and clicking inside of here i’m going to run f5 to refresh it and we now have our sql file right here that we’re gonna be working in now what are we gonna be quering well let’s go back to that cohort analysis and open it up things we definitely want are the customer key we have this clean name that we saw additionally we’re going to be using that order date and we can also use the first purchase date which will be used for some filtering that i’ll explain later so let’s start defining all this we’ll start with a select statement we’ll define that customer key the clean name the order date and that first purchase date and we want this all from cohort analysis okay let’s go ahead and run this looks like i don’t have any active connections so we’ll update it real quick to select the right data source and run all right so now we want to get well we’ll target specifically this customer 180 right here we have these two purchases we already have a column for the first purchase date but really we want to know when was their last purchase made in order to understand if they bought it within that sixmonth period so we need a way to go through and basically identify in a numerical way what is the most recent purchase and we can do this using row number and partitioning so right after order date i’ll enter inside of here and we’ll do row number we want to do a partition so we use the keyword over then we put inside parenthesis the partition by and specifically we want to partition it by that customer key and then we don’t want the we don’t want it assigning just numbers willy-nilly we want to actually specify it depending on the order date so we’ll do an order by specifying order date and we’ll name this as row number which you’ll typically see this written as rn okay let’s go ahead and run this and not bad now looking at customer 180 again we can see that we have the most recent purchase is actually number two so it goes one two we actually want it opposite of this so like their most recent purchase is numbered number one so i can change this order by to descending run this again pressing command enter and now we have it in that manner and it does order it we can also double check on some other ones here at 387 everything’s looking good so not looking bad we’re almost to what we need out of this mainly i don’t need any more duplicate duplicate entries i just want to get the most recent purchase out of here and that can be done by basically filtering for row number equal to one so what i’m going to do is put this all into a cte and then pull out what i actually need so i’m going to tab that over and we’ll give this the name of customer last purchase put it all within opening and closing parenthesis and then from here do a select statement we want that customer key clean name order date and we’re getting this from the customer last purchase remember we want to filter this right where that row number is equal to one go ahead and run this have a little typo in here put something i didn’t need to go ahead and rerun it all right looking good now order date technically now this order date is i mean it is an order date but it’s actually now the last purchase date so i’m actually going to rename this with an alias of last purchase date looking good we now need to get into classifying each one of these customers as whether they’re active or churned now i need to show you something real quick so i’m actually going to do underneath this another query we’re just going to look real quick at the order date column and that’s from the sales table i’m going to go ahead and just run just this query then i’m going to filter this in descending order and so what we can see is actually the most recent date this data ends on the 20th of april on 2024 now i can actually just query this by doing a max of the order date run controll enter and it’s still that 420 so why am i telling you this well as of filming this it is march of 2025 so we’re almost a year ahead anyway if we went back from my time now six months none of the customer there’s not any data in the system within that six-month period and so we’d have like a 0% act well we would have a 0% active rate so the point is we have to do this from our last data point of 6 months past this 420 or 6 months before 420 so what we’re going to do is this we want to now actually let’s go back and run up this query we want to now categorize these using a case statement looking back seeing if they’re within 6 months of april 20th 2024 and if that case classified as active otherwise classified as churned so in our main query down at the bottom i’m going to go ahead and put a case in and then we’ll do a when then we want to use this column we know it’s called order date when order date is less than 2024 of april 20th and specifically minus 6 months so within 6 months of that period so we’re going to do an interval specifying 6 months in this case we want to classify it then as churned so better said going back or doing this actual calculation right here if there are any purchases before october 20th 2023 we’re going to classify them as churned else we’re going to mark them as active and then we’re going to end this case statement also i want to give it an alias of customer status okay let’s go ahead and check this out i’m going to remove this extra line right here and now run command enter okay we got this error message right here invalid input syntax for type interval specifically right now for this we’re trying to do a comparison for order date basically 10 20 of 2023 this sees this as a string we need to actually cast this as a date using this operator go ahead and run command enter and now it is working now we have this extra column we can go through and actually double check it we can see here november 2023 is active december 2023 active and looks like it’s matching up pretty well now there’s one other thing or one minor detail that we need to actually filter correctly for to make sure we’re getting the right calculation i’m going to go ahead and filter this data to show what i mean all right this is it anyway these are the last purchase dates and actually this isn’t actually showing what i want to show we want to show first purchase date i’m going to show it right next to this so i’m going to call it first purchase date right here remember we have it up in the cte up above so i can just call it right here and whenever i run this it’s now here let me actually now filter by this okay this is what i’m trying to show their first purchase date was or these customers however shown was firstly on uh april 20th and there is active so if we keep scrolling back all of these for a number of period are active and so they haven’t been a customer really for six months yet so they’ve never even qualified to become churned i would argue that this would cause a bias to increase our numbers especially in 2024 for making it look like all of our customers are actually active actually and that’s what will happen in 2024 if i scroll all the way through here and we get to the beginning of the year all of these customers in 2024 will remain active when i run a percentage on this it’s going to say 100% active in 2024 which is completely useless we need to actually go back and remove everybody until 10:20 because that’s when it’s keeps on being active but then here this is when we actually start getting churn customers cuz we actually get customers that have been part of the system for greater than 6 months so all i’m going to do is we’re going to modify this query here at an a end and we want this for first purchase date basically all of this to categorize that a period of october 20th 2023 i’m going paste it right here now let’s go ahead and run this and i’m once again going to filter by that first purchase date and we don’t have a first purchase date now until after october or before october 20th when we actually start having churned and active customers so we’re going to have a lot better description or actually key statistics that actually match up with the data now we have this cleaned up we actually don’t need this first purchase date anymore that’s not something that marketing may necessarily need we now have that final table that i was getting at that we needed to get with customer key clean name when was their last purchase date and whether they are active or churned one minor note on this query i am not a fan of hard- coding values into a query because say we got a like a data dump and we get more recent data files this number may change in the system instead we could use something like a subquery so i’m going to put this all within to parentheses and then i’m going to just take this command exit and i’m going to place it right here and then also right here okay and then now whenever we run this we have exactly the same results that we had previously and this is much cleaner so way if those dates ever do change or we get new data into the system it will automatically update so we have the data or the table we need for marketing but now i want to take it a step further and actually perform an analysis on this and one we’re going to look at just holistically overall what is the active and churned rate for everybody and then we’ll finally break it down by cohort year to see how the cohorts are trending over time so let’s just get a percentage for the active and then the churned i’m going to make this now into another cte i love me some cte and we’ll call this one churned customers i’ll put that into open and closing parenthesis then for this we’re just going to start simple first i just want the customer status and i want to count of these on active verse churned for each so i’m just going to do a simple count and we’ll do this of the customer keys itself and we’ll name this as numbum customers we’re gain that from that churn customer cte and we did an aggregation so we also need to do a group by on customer status okay let’s go ahead and run this all right so not bad looking like we have around 4400 active and 4,200 churned i prefer percentages so we’re going to move forward to calculating that one thing real quick we don’t need to necessarily run distinct on this if i ran command enter still going to be the same values and that’s because in here we ended up filtering down to only where row number equals one so there should be technically only one customer key so i’m not going to i think that’s just a little unnecessary we’re not going to include it so now we need to get basically another column if you will of total customers i want to basically add these together should be around like 46,800 but if you see here we’re doing group by well we can actually use window functions to expand bigger because window functions are done after the aggregation so what we can do is we can use this once again this count here to get the counts of these keys but then we want to do a sum of this using a window function and we’re going to do this over but we’re not going to partition by any anything because we want to do all of this and we’re going to name this as total customers okay let’s go ahead and run this all right and we have i was little off on the math that’s actually 46,913 now we need to have both of these right if i just did sum and tried to run this we get an error along with if i just ran count we’d also get an error we have to do the count of them and then we want to do a sum of this to do all of this in order for it to work so now what we can do is we can divide these two values to get our percentage so i’ll take this first value here paste it down right here we’re going to divide by the total customers which is this command c command v and we’ll name this as status percentage okay let’s go ahead and run this and not too bad numbers there’s a lot of numbers here so i could just do a round function around all of this and i only really care about two decimal places we’ll go ahead and do this and now it’s down to 9% and 91% which comparing this to the industry i’m using some like perplex perplexity which is a chatbot that searched the internet to get some values anyway i asked it what’s a typical turn rate in the e-com in a e-commerce company and it says hey a turn rate of under 5% is considered good however the average turn rate for the e-commerce industry is around 22% so this one’s pretty or our company is a lot lower than industry standards all right let’s just take this one more step further and now we’re going to be forming or finding out what is this active versus churned rate for our cohort years and see how it progresses over the years now all we need for this is well we need to add another column on cohort year um but the problem is we actually need to import it higher up specifically it’s inside of our cohort analysis if i actually look inside of here you can see cohort year is there so after that first purchase date i’m going to add in cohort year and then in our second subquery i’m also going to add it in here now because we added these extra parameters up here we needed to add it into our group by to make sure that it’s working just fine specifically i’m going add in cohort year and i actually want cohort year before this okay let’s go ahead and just run this this isn’t going to be the correct calculations just yet and so we do have that cohort year inside of here we have that active verse churned as we can see we have our number of customers but our total customers are 46,000 the entire time basically this is all of our total customers and then this is driving our percentages down so for 2015 we have 1% and 6% together these two rows should equal 100% the problem is we’re dividing this 237 by 46,000 we don’t want the total customers per se we want to be the total customers of 2015 so conveniently all we have to do is inside of our window functions we just have to add in a partition by and we want to do it by cohort year so we add in cohort year go ahead and run command enter and i need to learn how to spell partition okay we got good syntax highlighting now all right and i’m seeing this this is it looks like it’s adds up to the correct amounts all right looking good i’m actually going to take this partition by and also throw it into our status percentage below so we have the correct status percentage calculated and now whenever i add up these two values it will equal 100% for all of these and as we we can see it goes from around 8% up to in more recent years up to 10% graphing it visually we can also see this trend that it’s slowly going up over the time from that 8% up to even 10% all right so only one thing left to do now is update our readme we already have our uh third sql file in there and actually i need to make sure that it’s saved so i’m going to command s it and now when i go inside of here i can see that okay we have our entire sql file next thing is our readme i’m going close out of this and make this more viewable so what did i add to the readme first i attached the readme which is linked apparently not correctly and it looks like i spelled analysis wrong so always double check your spelling anyway when updating it now whenever i click on this it actually directs right to it so it’s always good to go through and actually click any different hyperlinks or links that you attach with this next thing i went in to do is attach a visualization this one i had generated by chai gbt just copied and pasted it in and it puts that graph in that we previously had from there i moved into the key findings talking about how our churn rate stabilized around 90% for the last 2 to 3 years and then studying the fact of that retention rates are consistently low 8 to 10% way less than what the industry normal is and then finally cap it off with that newer cohorts are showing similar churn directories and basically we need to take action now to start improving these churn rates so what can we do with this data well we can work in the future to basically target those within the first year or two to improve that active rate from churned we can also combine this with other analysis and re-engage not only our churn customers but also our highv value churn customers so we can be really specific with our targeting taking this a step further we could use this analysis in predicting future churn rates and how a customer may act that goes more into data science and machine learning we’re not going to go into that but it is something that we could take away from this analysis now that we have our third and final question done we now need to get into finalizing our readme packaging it all up and putting it on github and then finally sharing on linkedin which conveniently we doing in the next chapter with that i’ll see you there and we don’t have any more practice problems for the remainder of this course so congratulations to everybody that’s been doing those practice problems with that see you in the next one welcome to this final chapter where we’re now going to go into sharing our project and first of all i want to congratulate you for making it this far and getting through this entire project it’s been quite an accomplishment thus far now this chapter only has two short lessons the first lesson which this one right here is going to be about how we can create our github repo and then our next lesson will be in actually sharing this github repo onto platform like linkedin so dialing into this lesson we’re going to be focusing on two core technologies that you may or may not be familiar with the first is git git is a version control system similar to like track changes in microsoft word anyway it tracks our changes and you can install on your computer and use it to track changes within files we’ll go more into depth of this as we go through this video but we’re going to be using git to create a repo or repository and we’re going to be pushing it into github github is an online platform that allows you to share remote repositories and remote being you can access it from anywhere and what’s great about this is it allows us to then share our project so what are the steps we’re going to be going through in this video well first thing we need to do is actually clean up that readme after that we’re going to do a deeper dive if you’re unfamiliar with repos git and github we’ll do an explanation of all of this thirdly we’ll move into installing git on your computer and getting this repo set up for those then to put onto github and then we’ll in the fourth and final one we’ll be synced between the two and i’ll show you how you can manage it so if you’ve been keeping up with your readme so far with all of the different analysis that we’ve done since the beginning there’s not a lot that we need to do to update this specifically we need to fill in an overview business questions and then finally any strategic recommendations we have from this the overview i just have this one sentence of hey it’s analysis of customer behavior retention and lifetime value for e-commerce company to improve customer retention and maximize revenue for three questions we bucket them into these three that we’ve gone into inant detail on each one of these not going to rehash it feel free to pause this video now copy whatever you want off of it after this you should have that analysis approach that we’ve gone through after each one of the questions and actually updated it to include everything we need and then finally our strategic recommendations i went through and bucket these based on our three different questions and i’ve outlined a lot of the key tactics that we can take away from it within those questions so i’m not going to rehash it here again but i highly encourage you to brainstorm and think through what are some strategic recommendations that you would take and then from there put it into this section final and last sections on technical details i just have information on what technologies were used so people are aware that yes i use postgress for this and i use chatgbt for the visualizations so this is looking good i’m going to go ahead and press command s or control s to save it and now we can get into our next steps of initializing a repo or publishing to github but i want to just cover some background knowledge first so the first concept to understand is what is a repository or as i’ll call it going forward a repo this is a personal library for your project and basically allows you to keep manage and record every change to all your different files within it like i hinted to before it’s like track changes in excel except we’re using a version control system like git in order to manage these changes and thus we can go and revisit previous editions of it if we need to now in order to create this repo we need to use a technology like git git is a free and open-source distributed version control system and it’s designed everything from small to large projects i use it all the time for my version control we’ll be installing it here in a second so what exactly is going on and how is this becoming a git repository well here is the files that kelly and i are working together for to build this course and it has all our different lesson plans in it we actually used git for the version control for building this course anyway on the surface we can see that it just has some folders and some files in there nothing special but whenever i go to unhide the hidden files on a mac i can do that by pressing command shift period it shows that there is other files in here specifically this git folder orgget folder dot being at the front mean that the file is hidden that’s why you can’t see it that’s why i unhide it anyway this tracks all the different changes inside of here of what’s going on inside of my project we don’t even need to attach that or touch it in order to adj make any adjustments it does it automatically as we go through and make changes and update the git but i just wanted to show it so you understand what is going on there i’m actually going to go back and hide it so now that we understand that git is the version control system and is what is used to create a repository we understand that there are actually two types of main repositories one is a local repository and the second is a remote repository local is as suggested it’s local it’s stored on your computer what i just showed you right here is in fact a local repository because it’s local you don’t need any internet connection it’s super fast and you can do this and it’s very common to do this for your initial development now remote repositories are stored on a server they obviously because they’re on a server and not local you need internet but because they’re now in a remote location they allow you to collaborate with others so once again i have that that local repository here but also that same repo is on github and this is a remote repository and github allows me to work with kelly as a contributor for us to work back and forth on different files so frankly it’s more than just a version control system it’s also great at collaborating with others anyway this is now bringing us into github which is one of the most popular tools for using git specifically it allows you to store those git repos here and then share them with the world so by the end of this video we’ll be publishing your project to github so you can make it publicly accessible so if it’s not clear git is the version control system it maintains that local repo and it also has uh some different command line tools we can actually type into it we’re not going to go into that in the video that’s out of scope and it’s open source and free so that’s why we’re using it github hosts these repositories it’s located via web browser interface and we can access it remotely so that way we can also collaborate with others let’s now get into actually setting up this repo and sharing it with the world we’re going to go through four different steps first we need to install git if you don’t have it second we need to create the repo within our project folder third we need to set up a github profile if you don’t have one already and then finally the fourth step we’re going to actually share it to github so let’s see if we have git before installing it i’m going to open a terminal that’s going to be what you use on a mac and on windows you should have the terminal available or you can open up a command prompt inside of here all i’m going to type is get and then d- version and click enter in my case i do have it installed so it’s going to say what the version is i don’t need to install it on the machine now if it’s not installed you’re likely to get an error message and next we can now go through actually installing it so navigate to get.sem.com and from there you’re going to download for your appro appropriate uh operating system for windows machines you’re just going to be going through the setup for this most modern computers are 64-bit so you should be fine with installing this if you have a newer computer anyway it’s going to walk you through a guey just leave all the default values the same and click okay all the way through for mac they have a couple of different options for you to install and all of them are through that command line or that terminal my recommended option is through homebrew and if you don’t have homebrew not a big deal you go to this link up here and all you have to do to install homebrew is just copy this entire code here and then paste it in and actually run it i’m not going to run it because i have homebrew installed then after it’s installed all you need to do is copy this command of brew install git and execute that in the terminal you’ll have git installed now once you have it installed you need to verify is it in fact installed all we have to do is run git attack version and it should output the version there now some of y’all may get an error when running this it’s going to say something like this please tell me who you are and it gives you the instructions run this get config message in order to provide your email and your name all you got to do is copy it and then paste it into your terminal you need to actually go through though now and actually update things like your name to what actually your name is along with that email address above and then all you got to do is press enter you’re done now we need to move on to the next steps of creating our repo creating our profile and sharing to github conveniently these steps specifically steps two and four can actually be done together if i navigate to vs code specifically you go to this source control tab right here they have two options inside of your project itself you can either initialize the repository or publish to github but publish to github actually initializes the repository and then publishes to github the important thing though is you need a github profile before you click this so if you navigate over to github.com on the homepage right there it has a sign up for you to enter your email in and then go through the sign up process to create a github account once you have that account all set up then we can proceed forward so now i can go back into vs code and in here remember i’m going to do publish to github because it’s also going to initialize our repository at the same time i’m going to click publish to github it’s going to prompt me that hey the extension github wants to sign in using github i want to allow this i select my account that i want to be associated with and then i’m navigated back to vs code it asks me this first do i want to create a private or public repository i wanted to do a public repository the next thing this is very important you get this right in the first try it is select which files should be included in the repo i don’t care about this ds store any of these hidden files per se which hidden files are anything with a dot in the front of it i do want my sql files in there i don’t need that bookmarks folder that diagrams folder that scripts folder i do need my images because they have the images for my analysis you could if you want include the scripts i don’t really care about that that’s just like throwaway scripts i’m not maintaining that in version control okay i have in my case five files selected i’m going to go ahead and select okay it’s be going through publishing and it says that hey this was successfully published to my github now what i’m going to do is navigate back to github and go to my repository i can just get to my repository or get it to my profile by clicking the name in the top upand corner one thing to note if you haven’t done this already i recommend filling out any of the different social information along with your name and adding a picture to make it look like you have a legit profile anyway if i want to look at the repos myself i can go up here to repositories tab and it has this project which i titled intermediate sql project i can go ahead and click on it and includes that images folder which i click into it has all three of my images next is my git ignore which basically ignores all those different files that we said hey don’t import into git so that’s why it’s there and you didn’t see it before then our three sql files and finally our readme which we talked about before the readme is actually going to appear down below in this section and this has all of our analysis on this homepage this is really great that it is all there this is actually the url that i would want to share to other people to showcase my work now there’s one last core concept that i want to go over before we conclude this on github and that’s on how to actually sync your profile with github or sync your project with github as you go along let’s say that we do have a change inside of our readme file itself specifically i’m going to go under analysis tools and not only do i use postgress but i also use things like dber and pg admin okay so i have these new changes in here i’m going to go ahead and do command s and save it i can now see based on these changes that we have an m next to this this means that this file is now modified and underneath the version control i can see i have this notification here for one and it’s telling me that the readme is in fact modified now just to show i’m going to refresh this page real quick just to show if i scroll on down these tools are not present here but we want to get them updated on the technical details up here so what we need to do is stage as you can see this is underneath changes we need to stage these changes in our local repository we need to give a message of what we did here and i’ll say you can just leave it super short i’m going to say we updated tools and i’m going to click commit and it’s going to say hey there are no stage changes to commit would you like to stage all of your changes and commit them directly basically previously we’d have to go through staging all the changes and then committing them we’re going to basically combine this step together and so i’m going to click yes now these are still not up on github this is only committed locally to our repo so what we’re going to do is now push it to our github repo by clicking sync changes and it’s going to say hey this action will pull and push commits from origin main which is the version that we want to get updated to in our repo we’re going to click okay and also i don’t want to show this again so i’m going click okay don’t show again so now we can see we went here from first commit to now our second commit updated tools and if i navigate over to the readme refresh this page we can now see that it is now added to it so that was an example of pushing our changes we can also pull changes basically if there are changes in our remote repo like when me and kelly work together she pushes those changes up i want to pull those changes but we’re going to just implement a change in here and then uh pull it from there so what i’m going to do is i inside of github here i can actually edit this file oh and let me actually show you what i’m going to edit so these images i have them around 50% i’m going to update this one this one’s just too big i’m going to update it to 50% i’m going to click edit and then i’m going to go to the code now this is slightly this is html code that i’m using for this i’m using an image tag you don’t need to necessarily do that all you need to understand is that i want to update the percentage and this is actually the image for question number three i want question number two oh which isn’t in an image tag so what i can do is copy this code from down here put it down and this says image what from our source specifically i want this image right here from this source so i’ll put this in we want the alt tag or the name of it to be cohort analysis and then for the width 50% height auto i’m going to go ahead and do this by the way you don’t need to necessarily use this uh html formatting for image this is just sort of fancy dancy i’m using to get this 50% anyway now that we’ve done these changes in the readme i’m going to go ahead and go hey i want to commit changes for the commit message i’m actually going to change it to more descriptive to update second image size if you want to do an extended description you can and i want to commit directly to the main branch i’m going to go ahead and commit changes now scrolling on down in that readme i can see that we have that image formatted correctly so our remote repository is updated but if i actually view our readme from our local repository we can see the number three image is pretty small but the second image is pretty big and it’s still using that other sorry it’s using our just markdown format for having our images so going over to version control we want to pull these changes down from github so i’m going to select more actions and specifically pull and we can see down below underneath it we not only have first commit update tools we now we have update second image size and closing this out and looking at this we can see from this that all the image sizes are now formatted correctly and i have that updated code here so remember there’s two main concepts that we got went over here one is pushing the changes and this is sending our local repository changes up into our remote repository in github and then secondly we can pull changes if there are any changes on the remote repository i can then pull them down into my local repository and then my local repository can be up todate now that was just a brief intro into git and github if you’re new to this and you want additional resources on it i have an entire youtube video on it a link up above and you’ll be able to go through and see even more detail to understand the ins and outs of git all right in the next lesson we’re gonna now that we have this public repository on github we’re going to go forward with sharing it on linkedin so with that see you in the next one all right welcome to this very last lesson once again congratulations for finishing that project it’s now time to get into sharing that github repo onto linkedin and we’re also going to be going through how those that purchase the course perks can also upload their course certificate which you’re going to get after completing your end of course survey so let’s navigate on over to linkedin you should have a profile if you don’t i highly recommend that you create one this is where employers are at and this is where they’re checking your work anyway i’m here on my profile in here they have sections on and about featured activity but what i care about is this section here on licenses and certifications this is where we’re going to be uploading your course certificate remember you complete the end of course survey i’ll be emailing it to you you’ll not only get a link but you can also download the physical certificate as well now if you’re not seeing licenses and certifications you can actually come all the way up to the top click add profile section and underneath recommended you can click add licenses and certifications anyway let’s add that certificate to it by clicking this plus icon from there you’ll go through and fill this all in here i filled in with intermediate sql for data analytics put me as the issuing organization i have the uh issue date of march 2025 the certificate never expires so you don’t put an expiration date in there’s a credential it id located on the certificate so put that in along with the url underneath skills you can list up to five skills i’d recommend these of postgress sql git github and dbaver finally i also like including the image of the certificate itself so i select add media and then add media and then attach the file itself in there give it an appropriate title from there click apply all right once you have everything in there all you got to do is click save and it’s there the next thing you’ll do is actually update this project because we have our certificate but we also part of this course a project so underneath this project section i’m going to click the add icon from there i give it a name of intermediate sql sales analysis short description that i stole from our readme fill in the five core skills that were saying from that certificate next is the media and i like to include a link specifically a link to the github repo so what i’m going to do is just grab this url right here and copy it and then paste it right into here and then click add i’m liking everything that it has for this i’m going to go ahead and click apply now that we have our media in we can do our start date i started this bad boy making this back in october of 2024 and i just finished it this month in march of 2025 if you worked on with somebody like kelly mcklly so i could add her as a contributor and i can associate other projects i don’t have that okay now i’d go through and click save and my project’s going to be updated to my linkedin the last thing i’m going to recommend to do is sharing a social media post on linkedin or making a post if you will of this project completion to let everybody know that you’ve done this in it i’d call out that you completed the course and also did the project don’t forget to tag me and kelly in this as it’s super awesome i love going through this and being able to see all the different work and i can comment on it as well once again congratulations on all the work that you’ve put into completing this course and also this project what are the next steps well i have coming up shortly in the next few months we’ll be releasing an advanced sql for data analytics course which i’ll link somewhere on here that you can go and check it out if you’re interested in with that don’t forget to follow me on linkedin and smash that like button see you in the next one
Affiliate Disclosure: This blog may contain affiliate links, which means I may earn a small commission if you click on the link and make a purchase. This comes at no additional cost to you. I only recommend products or services that I believe will add value to my readers. Your support helps keep this blog running and allows me to continue providing you with quality content. Thank you for your support!